Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
app
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
lib
unicaen
app
Commits
42ba438b
Commit
42ba438b
authored
2 years ago
by
Anthony Gautreau
Browse files
Options
Downloads
Plain Diff
Merge
parents
de80ad6d
1c5750b5
Branches
Branches containing commit
Tags
5.1.2
Tags containing commit
No related merge requests found
Pipeline
#16320
passed
2 years ago
Stage: publish
Changes
3
Pipelines
2
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
CHANGELOG.md
+12
-0
12 additions, 0 deletions
CHANGELOG.md
src/UnicaenApp/Exporter/Pdf.php
+90
-32
90 additions, 32 deletions
src/UnicaenApp/Exporter/Pdf.php
src/UnicaenApp/Form/View/Helper/FormControlGroup.php
+2
-24
2 additions, 24 deletions
src/UnicaenApp/Form/View/Helper/FormControlGroup.php
with
104 additions
and
56 deletions
CHANGELOG.md
+
12
−
0
View file @
42ba438b
CHANGELOG
=========
5.
1.1
-----
-
Suppression du fix pour bootstrap-select-1.14.0-beta2 donc nécessaité de passer à bootstrap-select-1.14.0-beta3 dans vos applis.
5.
1.0
-----
-
Exporteur PDF : nouvelles méthodes set(Footer|Header)ScriptToDefault() et set(Footer|Header)ScriptToNone().
5.
0.1
-----
-
[FIX] FormControlGroup : prise en compte de la classe CSS des labels de checkboxes.
5.
0.0
-----
-
Migration vers Bootstrap 5 (front-end).
...
...
This diff is collapsed.
Click to expand it.
src/UnicaenApp/Exporter/Pdf.php
+
90
−
32
View file @
42ba438b
<?php
namespace
UnicaenApp\Exporter
;
use
Laminas\View\Resolver\TemplatePathStack
;
use
Mpdf\Mpdf
as
mPDF
;
use
UnicaenApp\Exception\LogicException
;
use
UnicaenApp\Exception\RuntimeException
;
...
...
@@ -129,6 +130,13 @@ class Pdf implements ExporterInterface
*/
private
$logo
;
/**
* Chemin absolu du répertoire contenant les scripts de vue par défaut.
*
* @var string
*/
protected
$defaultScriptsDirPath
=
__DIR__
.
'/scripts'
;
/**
* Constructeur.
*
...
...
@@ -151,6 +159,9 @@ class Pdf implements ExporterInterface
$this
->
orientationPaysage
=
$orientationPaysage
;
$this
->
defaultFontSize
=
$defaultFontSize
;
$this
->
setHeaderScriptToDefault
();
$this
->
setFooterScriptToDefault
();
$this
->
setLogo
(
file_get_contents
(
__DIR__
.
"/../../../public/unicaen/app/img/logo-unicaen.png"
));
}
...
...
@@ -179,6 +190,32 @@ class Pdf implements ExporterInterface
return
$this
;
}
/**
* Spécifie qu'aucun script ne soit utilisé pour les entêtes de pages.
* Autrement dit, les pages du document PDF n'auront pas d'entête !
*
* @return self
*/
public
function
setHeaderScriptToNone
()
{
$this
->
headerScripts
=
array
();
return
$this
;
}
/**
* Restaure le script de vue par défaut pour les entêtes de pages (pages paires et impaires).
*
* @return self
*/
public
function
setHeaderScriptToDefault
()
{
$this
->
headerScripts
[
'O'
]
=
'header-odd.phtml'
;
$this
->
headerScripts
[
'E'
]
=
'header-even.phtml'
;
return
$this
;
}
/**
* Ajoute un script de vue à inclure dans le rendu du corps du document PDF.
*
...
...
@@ -243,6 +280,32 @@ class Pdf implements ExporterInterface
return
$this
;
}
/**
* Restaure le script de vue par défaut pour les pieds de pages (pages paires et impaires).
*
* @return self
*/
public
function
setFooterScriptToDefault
()
{
$this
->
footerScripts
[
'O'
]
=
'footer-odd.phtml'
;
$this
->
footerScripts
[
'E'
]
=
'footer-even.phtml'
;
return
$this
;
}
/**
* Spécifie qu'aucun script ne soit utilisé pour les pieds de pages.
* Autrement dit, les pages du document PDF n'auront pas de pied de page !
*
* @return self
*/
public
function
setFooterScriptToNone
()
{
$this
->
footerScripts
=
array
();
return
$this
;
}
/**
* Génère le document PDF et l'envoie éventuellement au navigateur.
*
...
...
@@ -366,7 +429,7 @@ class Pdf implements ExporterInterface
$parts
=
array
();
// styles de base fournis par la librairie Unicaen
if
(
file_exists
((
$filepath
=
$this
->
getD
efaultScriptsPath
()
.
'/pdf.css'
)))
{
if
(
file_exists
((
$filepath
=
$this
->
d
efaultScripts
Dir
Path
.
'/pdf.css'
)))
{
$css
=
file_get_contents
(
$filepath
);
$this
->
getMpdf
()
->
WriteHTML
(
$css
,
1
);
$parts
[]
=
$css
;
...
...
@@ -409,20 +472,20 @@ class Pdf implements ExporterInterface
if
(
isset
(
$this
->
headerScripts
[
'O'
]))
{
$headerOdd
=
$this
->
getRenderer
()
->
render
(
$this
->
headerScripts
[
'O'
],
$scriptVars
);
}
elseif
(
file_exists
(
$filepath
=
$this
->
getDefaultScriptsPath
()
.
'/header-odd.phtml'
))
{
ob_start
();
include
$filepath
;
$headerOdd
=
ob_get_clean
();
}
//
elseif (file_exists($filepath = $this->getDefaultScriptsPath() . '/header-odd.phtml')) {
//
ob_start();
//
include $filepath;
//
$headerOdd = ob_get_clean();
//
}
if
(
isset
(
$this
->
headerScripts
[
'E'
]))
{
$headerEven
=
$this
->
getRenderer
()
->
render
(
$this
->
headerScripts
[
'E'
],
$scriptVars
);
}
elseif
(
file_exists
(
$filepath
=
$this
->
getDefaultScriptsPath
()
.
'/header-even.phtml'
))
{
ob_start
();
include
$filepath
;
$headerEven
=
ob_get_clean
();
}
//
elseif (file_exists($filepath = $this->getDefaultScriptsPath() . '/header-even.phtml')) {
//
ob_start();
//
include $filepath;
//
$headerEven = ob_get_clean();
//
}
if
(
$headerOdd
)
{
$this
->
getMpdf
()
->
SetHTMLHeader
(
$headerOdd
,
'O'
);
...
...
@@ -498,20 +561,20 @@ class Pdf implements ExporterInterface
if
(
isset
(
$this
->
footerScripts
[
'O'
]))
{
$footerOdd
=
$this
->
getRenderer
()
->
render
(
$this
->
footerScripts
[
'O'
],
$scriptVars
);
}
elseif
(
file_exists
(
$filepath
=
$this
->
getDefaultScriptsPath
()
.
'/footer-odd.phtml'
))
{
ob_start
();
include
$filepath
;
$footerOdd
=
ob_get_clean
();
}
//
elseif (file_exists($filepath = $this->getDefaultScriptsPath() . '/footer-odd.phtml')) {
//
ob_start();
//
include $filepath;
//
$footerOdd = ob_get_clean();
//
}
if
(
isset
(
$this
->
footerScripts
[
'E'
]))
{
$footerEven
=
$this
->
getRenderer
()
->
render
(
$this
->
footerScripts
[
'E'
],
$scriptVars
);
}
elseif
(
file_exists
(
$filepath
=
$this
->
getDefaultScriptsPath
()
.
'/footer-even.phtml'
))
{
ob_start
();
include
$filepath
;
$footerEven
=
ob_get_clean
();
}
//
elseif (file_exists($filepath = $this->getDefaultScriptsPath() . '/footer-even.phtml')) {
//
ob_start();
//
include $filepath;
//
$footerEven = ob_get_clean();
//
}
if
(
$footerOdd
)
{
$this
->
getMpdf
()
->
SetHTMLFooter
(
$footerOdd
,
'O'
);
...
...
@@ -532,6 +595,11 @@ class Pdf implements ExporterInterface
public
function
setRenderer
(
PhpRenderer
$renderer
)
{
$this
->
renderer
=
$renderer
;
$this
->
renderer
->
resolver
()
->
attach
(
new
TemplatePathStack
([
'script_paths'
=>
[
$this
->
defaultScriptsDirPath
,
]]));
return
$this
;
}
...
...
@@ -595,16 +663,6 @@ class Pdf implements ExporterInterface
return
$this
->
mpdf
;
}
/**
* Retourne le chemin absolu du répertoire contenant les scripts de vue par défaut.
*
* @return string
*/
public
function
getDefaultScriptsPath
()
{
return
__DIR__
.
'/scripts'
;
}
/**
* Spécifie le chemin absolu dans lequel enregistrer le document PDF généré
* avec le paramètre DESTINATION_FILE.
...
...
This diff is collapsed.
Click to expand it.
src/UnicaenApp/Form/View/Helper/FormControlGroup.php
+
2
−
24
View file @
42ba438b
...
...
@@ -138,29 +138,6 @@ class FormControlGroup extends AbstractHelper
private
function
normalizeElement
(
ElementInterface
$element
)
{
// FIX pour "bootstrap-select-1.14.0-beta2" qui ne supporte pas les 'optgroup' avec Bootstrap 5 :
// on transforme en select sans optgroup (le nom du groupe est répété en tête de chaque option).
if
(
$element
instanceof
Select
)
{
$valueOptions
=
$element
->
getValueOptions
();
$newValueOptions
=
[];
foreach
(
$valueOptions
as
$key
=>
$value
)
{
if
(
is_array
(
$value
)
&&
array_key_exists
(
'options'
,
$value
))
{
// détection d'un optgroup !
$options
=
$value
[
'options'
];
$groupName
=
$value
[
'label'
];
foreach
(
$options
as
$k
=>
$v
)
{
if
(
is_array
(
$v
))
{
$k
=
$v
[
'value'
];
$v
=
$v
[
'label'
];
}
$newValueOptions
[
$k
]
=
$groupName
.
' > '
.
$v
;
// nom du groupe en tête de l'option
}
}
else
{
$newValueOptions
[
$key
]
=
$value
;
}
}
$element
->
setValueOptions
(
$newValueOptions
);
}
if
(
!
$element
instanceof
Button
&&
!
is_a
(
$element
,
Checkbox
::
class
))
{
$class
=
$element
->
getAttribute
(
'class'
);
$element
->
setAttribute
(
'class'
,
$class
.
' form-control'
);
...
...
@@ -296,10 +273,11 @@ class FormControlGroup extends AbstractHelper
$id
=
$element
->
getAttribute
(
'id'
);
$label
=
$element
->
getLabel
();
$title
=
$element
->
getLabelAttributes
()[
'title'
]
??
$element
->
getAttributes
()[
'title'
]
??
null
;
$class
=
$element
->
getLabelAttributes
()[
'class'
]
??
$element
->
getAttributes
()[
'class'
]
??
null
;
$html
=
<<<EOS
<div class="form-check">
$html
<label class="form-check-label" for="$id" title="$title">$label</label>
<label class="form-check-label
$class
" for="$id" title="$title">$label</label>
</div>
EOS;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment