Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Comptoir
Comptoir-srv
Commits
994099be
Commit
994099be
authored
Jun 09, 2020
by
Fabrice Gangler
🎨
Browse files
REFACTOR: add getBaseUrl() to AppController
parent
8e9f5370
Pipeline
#9972
passed with stage
in 4 minutes and 7 seconds
Changes
8
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
src/Controller/Api/V1/Taxonomy/CommonTaxonomyController.php
View file @
994099be
...
...
@@ -43,7 +43,7 @@ class CommonTaxonomyController extends MetaTaxonomyController
{
$firstLink
=
[
'name'
=>
__d
(
'Breadcrumbs'
,
'Taxonomy.index'
),
'url'
=>
$this
->
getBaseUrl
(
false
)
'url'
=>
$this
->
getBaseUrl
(
'mapping'
,
false
)
];
array_unshift
(
$links
,
$firstLink
);
parent
::
setBreadcrumbs
(
$links
);
...
...
src/Controller/Api/V1/Taxonomy/MetaTaxonomyController.php
View file @
994099be
...
...
@@ -159,23 +159,6 @@ class MetaTaxonomyController extends AppController
return
false
;
}
/**
* Before render callback.
* Called after the controller action is run, but before the view is rendered.
*
* Used to set view variables that are required on every request:
* - viewBaseUrl
*
* @param Event $event The beforeRender event.
* @return void
*/
public
function
beforeRender
(
Event
$event
)
{
parent
::
beforeRender
(
$event
);
$this
->
set
(
'viewBaseUrl'
,
$this
->
getBaseUrl
());
}
/**
* Business rules that define if current user is editor
*
...
...
@@ -197,25 +180,4 @@ class MetaTaxonomyController extends AppController
}
return
false
;
}
/**
* Returns the base URL of the mapping based on the user's language
*
* @param bool $withLanguagePrefix (optional) add the language prefix in the URL, by default it's true
* @return string base URL of the mapping based on the user's language.
*/
final
protected
function
getBaseUrl
(
$withLanguagePrefix
=
true
)
{
$url
=
''
;
if
(
$withLanguagePrefix
===
true
)
{
$url
.
=
'/'
.
$this
->
selectedLanguage
.
'/'
;
}
if
(
$this
->
selectedLanguage
===
'fr'
)
{
$url
.
=
'cartographie/'
;
}
else
{
$url
.
=
'mapping/'
;
}
return
$url
;
}
}
src/Controller/Api/V1/TaxonomysController.php
View file @
994099be
...
...
@@ -72,7 +72,7 @@ class TaxonomysController extends CommonTaxonomyController
// Check that the current URL is correct
$currentUrl
=
$this
->
request
->
here
(
false
);
$allowedUrl
=
$this
->
getBaseUrl
();
$allowedUrl
=
$this
->
getBaseUrl
(
'mapping'
);
if
(
$allowedUrl
!==
$currentUrl
)
{
return
$this
->
redirect
(
"
$allowedUrl
"
,
301
);
}
...
...
@@ -133,11 +133,11 @@ class TaxonomysController extends CommonTaxonomyController
// Some checks before display content
if
(
is_null
(
$primaryId
))
{
// if the requested primary level does not exist, redirect to the root mapping.
return
$this
->
redirect
(
$this
->
getBaseUrl
(),
301
);
return
$this
->
redirect
(
$this
->
getBaseUrl
(
'mapping'
),
301
);
}
else
{
// Check that the current URL is correct
$currentUrl
=
$this
->
request
->
here
(
false
);
$allowedUrl
=
$this
->
getBaseUrl
()
.
"
$primarySlug
/"
;
$allowedUrl
=
$this
->
getBaseUrl
(
'mapping'
)
.
"
$primarySlug
/"
;
if
(
$allowedUrl
!==
$currentUrl
)
{
return
$this
->
redirect
(
"
$allowedUrl
"
,
301
);
}
...
...
@@ -156,7 +156,7 @@ class TaxonomysController extends CommonTaxonomyController
$links
=
array
();
$links
[]
=
[
'name'
=>
$primaryName
,
'url'
=>
$this
->
getBaseUrl
(
false
)
.
"
$primarySlug
/"
,
'url'
=>
$this
->
getBaseUrl
(
'mapping'
,
false
)
.
"
$primarySlug
/"
,
];
$this
->
setBreadcrumbs
(
$links
);
}
...
...
@@ -207,14 +207,14 @@ class TaxonomysController extends CommonTaxonomyController
// Some checks before display content
if
(
is_null
(
$taxonId
))
{
// if the requested taxon does not exist, redirect to the root mapping.
return
$this
->
redirect
(
$this
->
getBaseUrl
(),
301
);
return
$this
->
redirect
(
$this
->
getBaseUrl
(
'mapping'
),
301
);
}
elseif
(
is_null
(
$parent_id
))
{
// if the requested taxon is a primary level, redirect it to the official URL.
return
$this
->
redirect
(
$this
->
getBaseUrl
()
.
"
$taxonSlug
/"
,
301
);
return
$this
->
redirect
(
$this
->
getBaseUrl
(
'mapping'
)
.
"
$taxonSlug
/"
,
301
);
}
else
{
// Check that the current URL is correct
$currentUrl
=
$this
->
request
->
here
(
false
);
$allowedUrl
=
$this
->
getBaseUrl
()
.
"
$primarySlug
/
$taxonSlug
/
$taxonId
"
;
$allowedUrl
=
$this
->
getBaseUrl
(
'mapping'
)
.
"
$primarySlug
/
$taxonSlug
/
$taxonId
"
;
if
(
$allowedUrl
!==
$currentUrl
)
{
return
$this
->
redirect
(
"
$allowedUrl
"
,
301
);
}
...
...
@@ -228,7 +228,7 @@ class TaxonomysController extends CommonTaxonomyController
$baseTaxonUrl
=
"
$primarySlug
/
$taxonSlug
"
;
$taxonName
=
$mappingTaxons
[
$taxonId
][
'title'
];
$this
->
set
(
'taxonId'
,
"
$taxonId
"
);
$this
->
set
(
'baseUrl'
,
$this
->
getBaseUrl
()
.
"
$baseTaxonUrl
"
);
$this
->
set
(
'baseUrl'
,
$this
->
getBaseUrl
(
'mapping'
)
.
"
$baseTaxonUrl
"
);
$this
->
set
(
'title'
,
"
$taxonName
"
);
$this
->
set
(
'data'
,
$data
);
$this
->
set
(
'_serialize'
,
[
'data'
]);
...
...
@@ -237,11 +237,11 @@ class TaxonomysController extends CommonTaxonomyController
$links
=
array
();
$links
[]
=
[
'name'
=>
$primaryName
,
'url'
=>
$this
->
getBaseUrl
(
false
)
.
"
$primarySlug
/"
,
'url'
=>
$this
->
getBaseUrl
(
'mapping'
,
false
)
.
"
$primarySlug
/"
,
];
$links
[]
=
[
'name'
=>
"
$taxonName
"
,
'url'
=>
$this
->
getBaseUrl
(
false
)
.
"
$baseTaxonUrl
/
$taxonId
"
,
'url'
=>
$this
->
getBaseUrl
(
'mapping'
,
false
)
.
"
$baseTaxonUrl
/
$taxonId
"
,
];
$this
->
setBreadcrumbs
(
$links
);
}
...
...
@@ -292,10 +292,10 @@ class TaxonomysController extends CommonTaxonomyController
// Some checks before load data
if
(
is_null
(
$taxonId
))
{
// the requested taxon does not exist, redirect to the root mapping.
return
$this
->
redirect
(
$this
->
getBaseUrl
(),
301
);
return
$this
->
redirect
(
$this
->
getBaseUrl
(
'mapping'
),
301
);
}
elseif
(
is_null
(
$parent_id
))
{
// the requested taxon is a primary level, redirect it to the official URL.
return
$this
->
redirect
(
$this
->
getBaseUrl
()
.
"
$taxonSlug
/"
,
301
);
return
$this
->
redirect
(
$this
->
getBaseUrl
(
'mapping'
)
.
"
$taxonSlug
/"
,
301
);
}
else
{
$parentTaxonUrl
=
"
$primarySlug
/"
;
$taxonUrl
=
$parentTaxonUrl
.
"
$taxonSlug
/
$taxonId
"
;
...
...
@@ -307,7 +307,7 @@ class TaxonomysController extends CommonTaxonomyController
$data
=
$this
->
TaxonomysSoftwares
->
getSoftwareTaxonomyWithUsers
(
$taxonId
,
$softwareId
);
if
(
!
isset
(
$data
)
||
!
is_array
(
$data
)
||
count
(
$data
)
===
0
)
{
// the requested IDs does not exist in database, redirect to the taxon page.
return
$this
->
redirect
(
$this
->
getBaseUrl
()
.
$taxonUrl
,
301
);
return
$this
->
redirect
(
$this
->
getBaseUrl
(
'mapping'
)
.
$taxonUrl
,
301
);
}
else
{
$software
=
$data
[
$softwareId
][
'software'
];
$softwareSlug
=
$software
->
slug_name
;
...
...
@@ -316,7 +316,7 @@ class TaxonomysController extends CommonTaxonomyController
// Check that the current URL is correct
$realCurrentUrl
=
$this
->
request
->
here
(
false
);
$allowedUrl
=
$this
->
getBaseUrl
()
.
$currentUrl
;
$allowedUrl
=
$this
->
getBaseUrl
(
'mapping'
)
.
$currentUrl
;
if
(
$allowedUrl
!==
$realCurrentUrl
)
{
return
$this
->
redirect
(
"
$allowedUrl
"
,
301
);
}
...
...
@@ -336,16 +336,16 @@ class TaxonomysController extends CommonTaxonomyController
$links
=
array
();
$links
[]
=
[
'name'
=>
$primaryName
,
'url'
=>
$this
->
getBaseUrl
(
false
)
.
$parentTaxonUrl
,
'url'
=>
$this
->
getBaseUrl
(
'mapping'
,
false
)
.
$parentTaxonUrl
,
];
$links
[]
=
[
'name'
=>
"
$taxonName
"
,
'url'
=>
$this
->
getBaseUrl
(
false
)
.
$taxonUrl
,
'url'
=>
$this
->
getBaseUrl
(
'mapping'
,
false
)
.
$taxonUrl
,
];
$links
[]
=
[
'name'
=>
"Utilisateurs du logiciel "
.
$software
->
softwarename
,
'name'
=>
"Logiciel "
.
$software
->
softwarename
,
'url'
=>
$this
->
getBaseUrl
(
false
)
.
$currentUrl
,
'url'
=>
$this
->
getBaseUrl
(
'mapping'
,
false
)
.
$currentUrl
,
];
$this
->
setBreadcrumbs
(
$links
);
}
...
...
src/Controller/Api/V1/TaxonomysSoftwaresController.php
View file @
994099be
...
...
@@ -76,7 +76,7 @@ class TaxonomysSoftwaresController extends CommonTaxonomySoftwareController
if
(
isset
(
$this
->
request
->
params
[
'softwareId'
]))
{
$softwareId
=
$this
->
request
->
params
[
'softwareId'
];
}
else
{
return
$this
->
redirect
(
$this
->
getBaseUrl
(),
301
);
return
$this
->
redirect
(
$this
->
getBaseUrl
(
'mapping'
),
301
);
}
}
...
...
@@ -86,7 +86,7 @@ class TaxonomysSoftwaresController extends CommonTaxonomySoftwareController
try
{
$software
=
$softwaresTable
->
get
(
$softwareId
);
}
catch
(
RecordNotFoundException
$e
)
{
// When there is no $softwareId record in database
return
$this
->
redirect
(
$this
->
getBaseUrl
(),
301
);
return
$this
->
redirect
(
$this
->
getBaseUrl
(
'mapping'
),
301
);
}
// Check that the current URL is correct
...
...
src/Controller/AppController.php
View file @
994099be
...
...
@@ -146,6 +146,7 @@ class AppController extends Controller
}
$this
->
set
(
'appVersion'
,
$this
->
appVersion
);
$this
->
set
(
'appFullBaseUrl'
,
Configure
::
read
(
'App.fullBaseUrl'
));
$this
->
set
(
'mappingBaseUrl'
,
$this
->
getBaseUrl
(
'mapping'
));
$this
->
set
(
'breadcrumbs'
,
$this
->
getBreadcrumbs
());
}
...
...
@@ -230,6 +231,33 @@ class AppController extends Controller
$this
->
set
(
'explicitLanguages'
,
$this
->
explicitLanguages
);
}
/**
* Returns the base URL based on the user's language
* Usage:
* - $this->getBaseUrl() = /fr/ or /en/
* - $this->getBaseUrl('mapping') = /fr/cartographie/ or /en/mapping/
*
* @param string $type (optional) allowed values : '' or 'mapping', by default it's ''
* @param bool $withLanguagePrefix (optional) add the language prefix in the URL, by default it's true
* @return string base URL based on the user's language.
*/
final
protected
function
getBaseUrl
(
string
$type
=
''
,
$withLanguagePrefix
=
true
)
{
$url
=
''
;
if
(
$withLanguagePrefix
===
true
)
{
$url
.
=
'/'
.
$this
->
selectedLanguage
.
'/'
;
}
if
(
$type
===
'mapping'
)
{
if
(
$this
->
selectedLanguage
===
'fr'
)
{
$url
.
=
'cartographie/'
;
}
else
{
$url
.
=
'mapping/'
;
}
}
return
$url
;
}
private
function
setOpenGraph
()
{
//For Social MEDIAS => OPENGRAPH
...
...
src/Template/Api/V1/Taxonomys/mapping.ctp
View file @
994099be
...
...
@@ -21,14 +21,14 @@
foreach
(
$mappingHead
as
$primaryId
=>
$primaryLevel
)
{
$primaryName
=
$mappingTaxons
[
$primaryId
][
'title'
];
$primarySlug
=
$mappingTaxons
[
$primaryId
][
'slug'
];
$url
=
"
$
view
BaseUrl
/
$primarySlug
/"
;
$url
=
"
$
mapping
BaseUrl
/
$primarySlug
/"
;
$linkPrimaryLevel
=
$this
->
Html
->
link
(
$primaryName
,
$url
,
[
'class'
=>
'button'
]);
$subLlist
=
[];
$htmlSubLlist
=
""
;
if
(
isset
(
$mappingTaxons
[
$primaryId
][
'children'
])){
foreach
(
$mappingTaxons
[
$primaryId
][
'children'
]
as
$subId
=>
$subName
)
{
$subSlug
=
$mappingTaxons
[
$subId
][
'slug'
];
$url
=
"
$
view
BaseUrl
/
$primarySlug
/
$subSlug
/
$subId
"
;
$url
=
"
$
mapping
BaseUrl
/
$primarySlug
/
$subSlug
/
$subId
"
;
$subLlist
[]
=
$this
->
Html
->
link
(
$subName
,
$url
);
}
$htmlSubLlist
=
$this
->
Html
->
nestedList
(
$subLlist
);
...
...
src/Template/Api/V1/Taxonomys/mapping_primary_level.ctp
View file @
994099be
...
...
@@ -23,7 +23,7 @@ $attId = "mappingPrimaryLevel$primaryId";
if
(
isset
(
$mappingTaxons
[
$primaryId
][
'children'
])){
foreach
(
$mappingTaxons
[
$primaryId
][
'children'
]
as
$subId
=>
$subName
)
{
$subSlug
=
$mappingTaxons
[
$subId
][
'slug'
];
$url
=
"
$
view
BaseUrl
/
$primarySlug
/
$subSlug
/
$subId
"
;
$url
=
"
$
mapping
BaseUrl
/
$primarySlug
/
$subSlug
/
$subId
"
;
$subLlist
[]
=
$this
->
Html
->
link
(
$subName
,
$url
);
}
echo
$this
->
Html
->
nestedList
(
$subLlist
);
...
...
src/Template/Element/Navigation/navbarFixedTop.ctp
View file @
994099be
...
...
@@ -12,6 +12,16 @@
if
(
!
isset
(
$appVersion
))
{
$appVersion
=
Cake\Core\Configure
::
read
(
"VERSION.footer"
);
}
// This template is used all the time (even on error pages).
// But, on error pages, the $mappingBaseUrl variable is not available.
// We force its creation that is always available.
if
(
!
isset
(
$mappingBaseUrl
))
{
$mappingBaseUrl
=
'/en/mapping/'
;
if
(
$selectedLanguage
===
'fr'
)
{
$mappingBaseUrl
=
'/fr/cartographie/'
;
}
}
?>
<div
class=
"navbar"
>
...
...
@@ -54,17 +64,13 @@
<
ul
class
=
"nav navbar-nav navbar-left nav-pull-down"
id
=
"navbar-mainMenu"
>
<?
php
$txtMapping
=
__d
(
"ElementNavigation"
,
"navbar.mapping"
)
;
$urlMapping
=
'/en/mapping/'
;
if
(
$selectedLanguage
===
'fr'
)
{
$urlMapping
=
'/fr/cartographie/'
;
}
?>
<?php
if
(
$this
->
isHere
(
"Taxonomys"
,
'mapping'
))
:
?>
<li
class=
"current"
>
<span
class=
" text-center"
>
<?=
__d
(
"ElementNavigation"
,
"navbar.mapping"
)
?>
</span>
</li>
<?php
else
:
?>
<li>
<?=
$this
->
Html
->
link
(
$txtMapping
,
$
urlM
apping
,
[
"id"
=>
"mappingPage"
])
?>
</li>
<li>
<?=
$this
->
Html
->
link
(
$txtMapping
,
$
m
apping
BaseUrl
,
[
"id"
=>
"mappingPage"
])
?>
</li>
<?php
endif
;
?>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment