Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/iCAPLyon1/WikiBundle into…
Browse files Browse the repository at this point in the history
… icon-change
  • Loading branch information
ngodfraind committed Jan 18, 2016
2 parents 66e8f06 + dedd490 commit 00b001f
Show file tree
Hide file tree
Showing 10 changed files with 212 additions and 18 deletions.
37 changes: 30 additions & 7 deletions Controller/WikiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
11 changes: 11 additions & 0 deletions Entity/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class Contribution
*/
protected $text;

protected $textForPdf;

/**
* @ORM\Column(type="datetime", name="creation_date")
* @Gedmo\Timestampable(on="create")
Expand Down Expand Up @@ -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
*/
Expand Down
4 changes: 2 additions & 2 deletions Listener/WikiListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -88,4 +88,4 @@ public function onCopy(CopyResourceEvent $event)
$event->setCopy($newWiki);
$event->stopPropagation();
}
}
}
1 change: 1 addition & 0 deletions Resources/public/css/pdf.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Resources/views/Section/deleteModal.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
23 changes: 15 additions & 8 deletions Resources/views/Wiki/view.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -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)) %}
<div class="wiki-header-buttons">
<a href="{{ path('icap_wiki_new_section', { 'wikiId': _resource.id, 'parentSectionId' : tree[0].id }) }}" class="new-section btn btn-primary" data-section="{{tree[0].id}}" >
<i class="fa fa-plus"></i> {{ 'create_new_section'|trans({}, 'icap_wiki') }}
</a>
{% if isAdmin %}
<a href="{{ path('icap_wiki_configure', { 'wikiId': _resource.id }) }}" class="btn btn-default"><i class="fa fa-wrench"></i> {{'options'|trans({},'icap_wiki')}}</a>
{% if user is not empty or config.getParameter('is_pdf_export_active') == true %}
<div class="wiki-header-buttons">
{% if user is not empty %}
{% if isAdmin or _resource.mode is not sameas(2)%}
<a href="{{ path('icap_wiki_new_section', { 'wikiId': _resource.id, 'parentSectionId' : tree[0].id }) }}" class="new-section btn btn-primary" data-section="{{tree[0].id}}" >
<i class="fa fa-plus"></i> {{ 'create_new_section'|trans({}, 'icap_wiki') }}
</a>
{% endif %}
{% if isAdmin %}
<a href="{{ path('icap_wiki_configure', { 'wikiId': _resource.id }) }}" class="btn btn-default"><i class="fa fa-wrench"></i> {{'options'|trans({},'icap_wiki')}}</a>
{% endif %}
{% render controller('IcapNotificationBundle:FollowerResource:renderForm', {'resourceId': _resource.resourceNode.id, 'resourceClass': _resource.resourceNode.class}) %}
{% endif %}
{% if config.getParameter('is_pdf_export_active') == true %}
<a href="{{ path('icap_wiki_view', {'wikiId':_resource.id, '_format':'pdf' }) }}" target="_blank" class="btn btn-default"><i class="fa fa-file-pdf-o text-danger"></i> {{ 'pdf_export'|trans({}, 'platform') }}</a>
{% endif %}
{% render controller('IcapNotificationBundle:FollowerResource:renderForm', {'resourceId': _resource.resourceNode.id, 'resourceClass': _resource.resourceNode.class}) %}
</div>
{% endif %}
{% endblock %}
Expand Down
37 changes: 37 additions & 0 deletions Resources/views/Wiki/view.pdf.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>{{ _resource.resourceNode.name ~ '.pdf' }}</title>
{% stylesheets debug=false filter='lessphp' output='bundles/icapwiki/css/pdf.css'
"@IcapWikiBundle/Resources/views/less/pdf.less"
%}
<link rel="stylesheet" type="text/css" href="{{ app.request.getSchemeAndHttpHost() ~ asset_url }}"/>
{% endstylesheets %}
</head>
<body>
<div class="page-header">
<h1>{{ _resource.resourceNode.name }}</h1>
</div>
{% if tree is not empty and tree[0] is not empty and tree[0].activeContribution.text is not empty%}
<div>
{{ tree[0].activeContribution.text|raw }}
</div>
{% endif %}

{% if tree is not empty and tree[0] is not empty and tree[0].__children is not empty %}
<div class="pdf-contents">
<div class="pdf-contents-inner well">
<div class="pdf-contents-title">
{{ 'wiki_contents'|trans({},'icap_wiki') }}
</div>
{% include "IcapWikiBundle:Wiki:wikiContents.pdf.twig" with {'sections' : tree[0].__children, 'isAdmin' : isAdmin, 'delimeter' : '.', 'rootId' : tree[0].id } %}
</div>
<div class="clearfix"></div>
</div>
<div class="wiki-sections">
{% include "IcapWikiBundle:Wiki:wikiSections.pdf.twig" with {'sections' : tree[0].__children, 'wikiId' : _resource.id, 'isAdmin' : isAdmin, 'wikiMode' : _resource.mode, 'user' : user } %}
</div>
{% endif %}
</body>
</html>
20 changes: 20 additions & 0 deletions Resources/views/Wiki/wikiContents.pdf.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{% macro wiki_contents_pdf(sections, isAdmin, delimeter, prefix) %}
{% for section in sections %}
{% if section.visible %}
<li id="li-{{ section.id }}">
<a href="#section-{{section.id}}">
{{prefix ~ loop.index}}&nbsp;{{ section.activeContribution.title }}
</a>
<ul id="ul-{{ section.id }}" class="no-bullet-list">
{% if section.__children is not empty %}
{{ _self.wiki_contents_pdf(section.__children, isAdmin, delimeter, prefix ~ loop.index ~ delimeter) }}
{% endif %}
</ul>
</li>
{% endif %}
{% endfor %}
{% endmacro %}

<ul id="wiki-contents-list" class="no-bullet-list">
{{ _self.wiki_contents_pdf(sections, isAdmin, delimeter, "") }}
</ul>
26 changes: 26 additions & 0 deletions Resources/views/Wiki/wikiSections.pdf.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{% macro wiki_sections_pdf(sections, isAdmin, wikiId, wikiMode, user) %}
{% for section in sections %}
{% if section.deleted is empty and section.visible %}
{% set level = section.level + 1 %}
{% set fontsize = 0 %}
{% if level > 4 %}
{% set level = 4 %}
{% endif %}
<li id="section-{{section.id}}" class="section-title">
<div class="{{level>2?"subsection-header":"page-header"}}">
<h{{level}}>{{section.activeContribution.title}}</h{{level}}>
</div>
<div id="wst-{{ section.id }}" class="wiki-section-text">{{section.activeContribution.text|preg_replace("/src=\"\\/\\//","src=\"http://")|preg_replace("/src=\"\\//","src=\""~app.request.getSchemeAndHttpHost()~"/")|raw}}</div>
{% if section.__children is not empty %}
<ul class="no-bullet-list">
{{ _self.wiki_sections_pdf(section.__children, isAdmin, wikiId, wikiMode, user) }}
</ul>
{% endif %}
</li>
{% endif %}
{% endfor %}
{% endmacro %}

<ul id="wiki-sections-list" class="no-bullet-list">
{{ _self.wiki_sections_pdf(sections, isAdmin, wikiId, wikiMode, user) }}
</ul>
69 changes: 69 additions & 0 deletions Resources/views/less/pdf.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
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{
ul{margin-left: 10px;}
display: block;
margin-left: 0px;
padding-left: 0px;
}

table{
border-color: #ccc;
border-width: 0 0 1px 1px;
border-style: solid;
border-spacing: 0px;
border-collapse: separate;
td, 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;}

0 comments on commit 00b001f

Please sign in to comment.