diff --git a/Controller/WikiController.php b/Controller/WikiController.php index 7d4013f..6d34d11 100755 --- a/Controller/WikiController.php +++ b/Controller/WikiController.php @@ -33,28 +33,51 @@ class WikiController extends Controller{ /** * @Route( - * "/{wikiId}", - * requirements={"wikiId" = "\d+"}, + * "/{wikiId}.{_format}", + * defaults={"_format":"html"}, + * requirements={"wikiId" = "\d+", "_format":"html|pdf"}, * name="icap_wiki_view" * ) * @ParamConverter("wiki", class="IcapWikiBundle:Wiki", options={"id" = "wikiId"}) - * @Template() */ - public function viewAction(Wiki $wiki) + public function viewAction(Wiki $wiki, Request $request) { $this->checkAccess("OPEN", $wiki); $isAdmin = $this->isUserGranted("EDIT", $wiki); $user = $this->getLoggedUser(); $sectionRepository = $this->get('icap.wiki.section_repository'); $tree = $sectionRepository->buildSectionTree($wiki, $isAdmin); - - return array( + $format = $request->get('_format'); + $response = new Response(); + $this->render(sprintf('IcapWikiBundle:Wiki:view.%s.twig', $format), array( '_resource' => $wiki, 'tree' => $tree, 'workspace' => $wiki->getResourceNode()->getWorkspace(), 'isAdmin' => $isAdmin, 'user' => $user - ); + ), $response); + if ($format == "pdf") { + return new Response( + $this->get('knp_snappy.pdf')->getOutputFromHtml( + $response->getContent(), + array( + 'outline' => true, + 'footer-right' => '[page]/[toPage]', + 'footer-spacing' => 3, + 'footer-font-size' => 8 + ), + true + ), + 200, + array( + 'Content-Type' => 'application/pdf', + 'Content-Disposition' => 'inline; filename="'.$wiki->getResourceNode()->getName() + ) + ); + + } + + return $response; } /** diff --git a/Entity/Contribution.php b/Entity/Contribution.php index 204f001..aeffa49 100755 --- a/Entity/Contribution.php +++ b/Entity/Contribution.php @@ -35,6 +35,8 @@ class Contribution */ protected $text; + protected $textForPdf; + /** * @ORM\Column(type="datetime", name="creation_date") * @Gedmo\Timestampable(on="create") @@ -91,6 +93,15 @@ public function getText() return $this->text; } + public function getTextForPdf() + { + $tmpText = $this->text; + str_replace(" ", " ", $tmpText); + preg_replace('/alt=["\'][a-zA-Z]*["\']/g', "", $tmpText); + + return $tmpText; + } + /** * @param mixed $text */ diff --git a/Listener/WikiListener.php b/Listener/WikiListener.php index 8fdfa01..d3b9fcf 100755 --- a/Listener/WikiListener.php +++ b/Listener/WikiListener.php @@ -72,7 +72,7 @@ public function onOpen(OpenResourceEvent $event) public function onDelete(DeleteResourceEvent $event) { - $em = $this->container->get('doctrine.orm.entity_manager'); + $em = $this->container->get('claroline.persistence.object_manager'); $em->remove($event->getResource()); $em->flush(); $event->stopPropagation(); @@ -88,4 +88,4 @@ public function onCopy(CopyResourceEvent $event) $event->setCopy($newWiki); $event->stopPropagation(); } -} \ No newline at end of file +} diff --git a/Resources/public/css/pdf.css b/Resources/public/css/pdf.css new file mode 100644 index 0000000..66ea0d8 --- /dev/null +++ b/Resources/public/css/pdf.css @@ -0,0 +1 @@ +html,body{font-family:Arial, 'Helvetica Neue', Helvetica, sans-serif;font-size:12px}h1,h2,h3,h4,h5,h6{margin:10px 0;font-weight:500}h1{font-size:20px}h2{font-size:16px}h3{font-size:14px}h4{font-size:12px}a{color:#2a6496}ul{display:block;margin-left:0px;padding-left:0px}ul ul{margin-left:10px}table{border-color:#ccc;border-width:0 0 1px 1px;border-style:solid;border-spacing:0px;border-collapse:separate}table td,table th{border-width:1px 1px 0 0;border-style:solid;margin:0;padding:4px;border-color:#ccc}div.pdf-contents div.pdf-contents-inner{float:left;border:1px solid #e3e3e3;padding:10px;min-width:200px}ul.no-bullet-list{list-style:none}.page-header{border-bottom:1px solid #eeeeee}.subsection-header{border-bottom:1px dashed #eeeeee}.clearfix,.clearfix::after{clear:both} \ No newline at end of file diff --git a/Resources/views/Section/deleteModal.html.twig b/Resources/views/Section/deleteModal.html.twig index 8d0f2eb..ea19d05 100755 --- a/Resources/views/Section/deleteModal.html.twig +++ b/Resources/views/Section/deleteModal.html.twig @@ -21,7 +21,7 @@ $('form[id="deleteSection-form-{{ section.id }}"] > input[type="submit"]').hide(); $('form[id="deleteSection-form-{{ section.id }}"] > a.cancel-btn').hide(); - $('#deleteSectionModal-submit-{{ section.id }}').on('click', function () { + $('#deleteSectionModal-submit-{{ section.id }}').on('click', function (event) { event.preventDefault(); //I do the "click" on submit button for keep html5 warning $('form[id="deleteSection-form-{{ section.id }}"] > input[type="submit"]').trigger('click'); diff --git a/Resources/views/Wiki/view.html.twig b/Resources/views/Wiki/view.html.twig index 39f30d2..963e39c 100755 --- a/Resources/views/Wiki/view.html.twig +++ b/Resources/views/Wiki/view.html.twig @@ -5,15 +5,22 @@ {% block title %}{{ _resource.resourceNode.name }}{% endblock %} {% block wiki_buttons %} - {% if user is not empty and (isAdmin or _resource.mode is not sameas(2)) %} -