Commit db4e0dbd authored by Arnaud Bey's avatar Arnaud Bey

add export options (metadatas or not, xsl or not)

parent 3007b0ba
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.tei-c.org/ns/1.0">
<xsl:output method="xml" encoding="UTF-8" indent="yes"/>
<xsl:template match="xml">
<TEI xmlns="http://www.tei-c.org/ns/1.0">
<xsl:apply-templates select="tact_metadatas"/>
<facsimile>
<surface >
<xsl:attribute name="xml:id">
<xsl:value-of select="//tact_media_url"/>
</xsl:attribute>
</surface>
</facsimile>
<text>
<body>
<xsl:apply-templates select="body"/>
</body>
</text>
</TEI>
</xsl:template>
<xsl:template match="tact_metadatas">
<teiHeader>
<fileDesc>
<titleStmt>
<title>
Transcription de <xsl:value-of select="//tact_media_name"/>
</title>
<xsl:apply-templates select="//tact_media_contributor"/>
</titleStmt>
<editionStmt>
<p>
Transcription effectuée sur la plateforme TACT: <xsl:value-of select="//tact_platform_url"/>
Etat de la fiche sur TACT : <xsl:value-of select="//tact_media_status"/>
</p>
</editionStmt>
<publicationStmt>
<publisher>Laboratoire Litt&amp;Arts</publisher>
<date>
<xsl:attribute name="when">
<xsl:value-of select="//tact_media_export_date"/>
</xsl:attribute>
</date>
</publicationStmt>
<sourceDesc>
<p>Texte transcrit</p>
</sourceDesc>
</fileDesc>
</teiHeader>
</xsl:template>
<xsl:template match="body">
<xsl:value-of select="."/>
</xsl:template>
<xsl:template match="tact_media_contributor">
<respStmt>
<resp><xsl:value-of select="//role"/></resp>
<name type="username"><xsl:value-of select="//name"/></name>
</respStmt>
</xsl:template>
</xsl:stylesheet>
......@@ -91,6 +91,8 @@ class ProjectController extends AbstractController
$params = [
'medias' => $form->get('medias')->getData(),
'transcriptions' => $form->get('transcriptions')->getData(),
'metadatas' => $form->get('transcriptions_metadatas')->getData(),
'xsl' => $form->get('transcriptions_apply_xsl')->getData(),
'transcriptionsList' => $form->get('transcriptions_list')->getData(),
'usersList' => $form->get('users_list')->getData(),
'infos' => $form->get('project_infos')->getData()
......
......@@ -20,6 +20,16 @@ class ExportType extends AbstractType
'label' => 'export_transcriptions',
'required' => false
])
->add('transcriptions_metadatas', CheckboxType::class, [
'label' => 'export_transcriptions_metadatas',
'required' => false,
'help' => "export_transcriptions_metadatas_help"
])
->add('transcriptions_apply_xsl', CheckboxType::class, [
'label' => 'export_transcriptions_apply_xsl',
'required' => false,
'help' => "export_transcriptions_apply_xsl_help"
])
->add('transcriptions_list', CheckboxType::class, [
'label' => 'export_transcriptions_list',
'required' => false
......
......@@ -11,11 +11,11 @@ use Symfony\Component\Filesystem\Exception\IOExceptionInterface;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Finder\Finder;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Serializer\Encoder\CsvEncoder;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
use Symfony\Component\Serializer\Serializer;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
class ExportManager
{
......@@ -26,6 +26,7 @@ class ExportManager
protected $translator;
protected $tm;
protected $router;
protected $userRepo;
public function __construct(EntityManagerInterface $em, FileManager $fileManager, TranslatorInterface $translator, TranscriptionManager $tm, UrlGeneratorInterface $router)
{
......@@ -33,6 +34,7 @@ class ExportManager
$this->tm = $tm;
$this->mediaRepo = $repository = $this->em->getRepository('App:Media');
$this->dirRepo = $repository = $this->em->getRepository('App:Directory');
$this->userRepo = $repository = $this->em->getRepository('App:User');
$this->fileManager = $fileManager;
$this->translator = $translator;
$this->router = $router;
......@@ -202,7 +204,9 @@ class ExportManager
$fullTranscriptionFilePath = $transcriptionPath.DIRECTORY_SEPARATOR.$media->getName();
if ($params["transcriptions"]) {
$fileSystem->appendToFile($fullTranscriptionFilePath.'.xml', $this->generateXML($media));
$withMetadatas = $params["metadatas"];
$withXsl = $params["xsl"];
$fileSystem->appendToFile($fullTranscriptionFilePath.'.xml', $this->generateXML($media, $withMetadatas, $withXsl));
}
if ($params["medias"] && $media->getUrl()) {
......@@ -241,13 +245,15 @@ class ExportManager
return false;
}
public function generateXML(Media $media)
public function generateXML(Media $media, $withMetadatas = true, $withXsl = true)
{
$project = $media->getProject();
$transcription = $media->getTranscription()->getContent();
$xslFile = $this->fileManager->getProjectPath($project).DIRECTORY_SEPARATOR."export.xsl";
$header = $withMetadatas ? $this->generateHeader($media) : "";
$header = preg_replace("/<\?xml[^<>]+>\s/", "", $header);
if (file_exists($xslFile)) {
if (file_exists($xslFile) && $withXsl) {
$xsl = new \DOMDocument();
$xsl->load($xslFile);
......@@ -255,13 +261,95 @@ class ExportManager
$xslt->importStylesheet($xsl);
$xml = new \DOMDocument();
$xml->loadXML("<body>".$transcription."</body>");
$xml->loadXML("<xml>".$header."<body>".$transcription."</body></xml>");
$xml->xinclude(LIBXML_NOWARNING);
return $xslt->transformToXML($xml);
$output = $xslt->transformToXML($xml);
return $output;
}
$output = $header."\n".$transcription;
return $output;
}
private function generateHeader(Media $media)
{
$transcription = $media->getTranscription();
$contributors = $this->tm->getContributors($transcription);
$status = $this->translator->trans("transcription_status_".$this->tm->getStatus($transcription));
$project = $media->getProject();
$mediaParts = pathinfo($media->getUrl());
$mediaRealName = $media->getName() . "." . $mediaParts["extension"];
$platformUrl = $this->router->generate('home', [], UrlGeneratorInterface::ABSOLUTE_URL);
$projectUrl = $this->router->generate('project_display', ["id" => $project->getId()], UrlGeneratorInterface::ABSOLUTE_URL);
$platformContributors = ["ELAN","Démarre SHS !"];
$xml = new \DOMDocument(LIBXML_NOXMLDECL);
$xmlMetadatas = $xml->createElement("tact_metadatas");
// PLATFORM
$xmlPlatform = $xml->createElement("tact_platform");
$xmlPlatformUrl = $xml->createElement("tact_platform_url", $platformUrl);
$xmlPlatformContributors = $xml->createElement("tact_platform_contributors");
foreach ($platformContributors as $platformContributor) {
$xmlPlatformContributor = $xml->createElement("tact_platform_contributor", $platformContributor);
$xmlPlatformContributors->appendChild($xmlPlatformContributor);
}
$xmlPlatform->appendChild($xmlPlatformUrl);
$xmlPlatform->appendChild($xmlPlatformContributors);
$xmlMetadatas->appendChild($xmlPlatform);
// PROJECT
$xmlProject = $xml->createElement("tact_project");
$xmlProjectName = $xml->createElement("tact_project_name", $media->getProject()->getName());
$xmlProjectUrl = $xml->createElement("tact_project_url", $projectUrl);
$xmlProjectManagers = $xml->createElement("tact_project_managers");
$xmlProject->appendChild($xmlProjectName);
$xmlProject->appendChild($xmlProjectUrl);
$projectManagers = $this->userRepo->getManagersByProject($project);
foreach ($projectManagers as $projectManager) {
$xmlProjectManager = $xml->createElement("tact_project_manager", $projectManager->getUsername());
$xmlProjectManagers->appendChild($xmlProjectManager);
}
$xmlProject->appendChild($xmlProjectManagers);
$xmlMetadatas->appendChild($xmlProject);
// MEDIA
$xmlMedia = $xml->createElement("tact_media");
$xmlMediaName = $xml->createElement("tact_media_name", $media->getName());
$xmlMediaUrl = $xml->createElement("tact_media_url", $mediaRealName);
$xmlMediaStatus = $xml->createElement("tact_media_status", $status);
$xmlMediaExportDate = $xml->createElement("tact_media_export_date", date('Y-m-d\TH:i:s'));
$xmlMediaContributors = $xml->createElement("tact_media_contributors");
foreach ($contributors as $contributor) {
$userProjectStatus = $this->em->getRepository("App:UserProjectStatus")->findOneBy(["user"=> $contributor, "project" => $project]);
$status = ($userProjectStatus && $userProjectStatus->getEnabled()) ? $userProjectStatus : null;
$statusName = ($status) ? $status->getStatus()->getName() : "user_status_transcriber_name";
$xmlMediaContributor = $xml->createElement("tact_media_contributor");
$xmlMediaContributorName = $xml->createElement("name", $contributor->getUsername());
$xmlMediaContributorRole = $xml->createElement("role", $this->translator->trans($statusName));
$xmlMediaContributor->appendChild($xmlMediaContributorName);
$xmlMediaContributor->appendChild($xmlMediaContributorRole);
$xmlMediaContributors->appendChild($xmlMediaContributor);
}
$xmlMedia->appendChild($xmlMediaContributors);
$xmlMedia->appendChild($xmlMediaName);
$xmlMedia->appendChild($xmlMediaExportDate);
$xmlMedia->appendChild($xmlMediaStatus);
$xmlMedia->appendChild($xmlMediaUrl);
$xmlMetadatas->appendChild($xmlMedia);
$xml->appendChild($xmlMetadatas);
$xml->preserveWhiteSpace = false;
$xml->formatOutput = true;
return $transcription;
return html_entity_decode($xml->saveXml(null, LIBXML_NOXMLDECL));
}
private function arrayToCsv($array)
......
......@@ -15,8 +15,6 @@
{% include 'header.html.twig' with {'title': 'project_create'} %}
{% endif %}
<div id="main-container">
{{ form_start(form) }}
{{ form_row(form.css) }}
......@@ -32,6 +30,7 @@
</button>
</div>
{% endif %}
<span class="text-muted small">Vous trouverez <a download href="{{ asset("xslt/xsl-exemple.xsl") }}">ici</a> un exemple de xsl</span>
</div>
<div class="col">
{{ form_label(form.json_schema) }}
......@@ -42,7 +41,6 @@
<span class="text-muted small">{{"tei2json_help"|trans|raw}}</span>
</div>
{% if project|hasScheme %}
<div class="project-json-row">
<a download href="{{ asset('project_files/'~ project.id ~ '/tei-schema.json') }}">tei-schema.json</a>
......
......@@ -4,7 +4,15 @@
{% include 'project/navigation.html.twig' with {'current': 'project_export'} %}
<div id="main-container">
<h5>{{"export_form_title"|trans}}</h5>
{{form(form)}}
{{ form_start(form) }}
{{ form_widget(form._token) }}
{{ form_row(form.transcriptions) }}
<div class="ml-4">
{{ form_row(form.transcriptions_apply_xsl) }}
{{ form_row(form.transcriptions_metadatas) }}
</div>
{{ form_end(form) }}
{{ form_row(form.save) }}
</div>
{% endblock %}
......
......@@ -61,6 +61,10 @@ email_or_login: Please enter your login or email
email: Mail
events: Evénements
export_project_long: Permet d'exporter tout ou partie du projet
export_transcriptions_apply_xsl_help: Si une XSL est définie pour le projet, elle sera appliquée.
export_transcriptions_apply_xsl: Appliquer la XSL
export_transcriptions_metadatas_help: Des métadonnées concernant la transcription et le projet seront injectées dans le XML.
export_transcriptions_metadatas: Les métadonnées dans les transcriptions
export: Exporter
faq: Frequently asked questions
filter_users_by: Filter by lastname / firstname / mail / login
......@@ -294,6 +298,7 @@ transcription_saved: Transcription saved
transcription_send_to_validation: Send to validation
transcription_status_in_progress: In progress
transcription_status_in_reread: Reread
transcription_status_in-reread: Transcription en relecture
transcription_status_no_transcription: None
transcription_status_none: No transcript
transcription_status_validated: Finished
......
......@@ -65,7 +65,11 @@ export_launch: Lancer l'export
export_medias: Les médias
export_project_infos: Les données du projets (schéma, etc.)
export_project_long: Permet d'exporter tout ou partie du projet
export_transcriptions_apply_xsl_help: Si une XSL est définie pour le projet, elle sera appliquée.
export_transcriptions_apply_xsl: Appliquer la XSL
export_transcriptions_list: La liste des transcriptions
export_transcriptions_metadatas_help: Des métadonnées concernant la transcription et le projet seront injectées dans le XML.
export_transcriptions_metadatas: Les métadonnées dans les transcriptions
export_transcriptions: Les transcriptions
export_users_list: La liste des utilisateurs
export: Exporter
......@@ -308,6 +312,7 @@ transcription_saved: Transcription sauvegardée
transcription_send_to_validation: Demander une relecture
transcription_status_in_progress: Transcription en cours
transcription_status_in_reread: Transcription en relecture
transcription_status_in-reread: Transcription en relecture
transcription_status_no_transcription: Aucune transcription
transcription_status_none: Aucune transcription
transcription_status_validated: Transcription terminée
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment