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
Amaury Van Espen
costum
Commits
24d3acc1
Commit
24d3acc1
authored
Dec 18, 2019
by
Tibor Katelbach
Browse files
costumBuildr and repaired context Id switch
parent
e161e238
Changes
7
Hide whitespace changes
Inline
Side-by-side
README.md
View file @
24d3acc1
...
...
@@ -95,7 +95,7 @@ The conception of costum based on of communecter's parameters is a basic version
<br/>
# generic COstum (templates)
# generic COstum (templates)
: reusable by many elements
Imagine having created a costum (templateSlug)
and you want to reuse exactly the same in a different context
This is possible with
*generic costums*
with a parent element(elementSlug)
...
...
controllers/actions/IndexAction.php
View file @
24d3acc1
...
...
@@ -19,21 +19,28 @@ class IndexAction extends CAction
$controller
->
layout
=
"//layouts/mainSearch"
;
//$params = CO2::getThemeParams();
//Yii::app()->session['paramsConfig']=$params;
Costum
::
init
(
$this
->
getController
(),
$id
,
$type
,
$slug
,
$view
,
$test
);
Costum
::
init
(
$this
->
getController
(),
$id
,
$type
,
$slug
,
$view
,
$test
,
"costum/controllers/actions/IndexAction.php"
);
if
(
$page
&&
Yii
::
app
()
->
session
[
'costum'
][
"welcomeTpl"
]){
//use another page inside the same costum folder
if
(
$page
&&
Yii
::
app
()
->
session
[
'costum'
][
"welcomeTpl"
])
{
$path
=
explode
(
"."
,
Yii
::
app
()
->
session
[
'costum'
][
"welcomeTpl"
]);
array_pop
(
$path
);
$path
[]
=
$page
;
echo
$controller
->
render
(
implode
(
"."
,
$path
),
array
()
,
true
);
echo
$controller
->
render
(
implode
(
"."
,
$path
),
[]
,
true
);
}
else
if
(
@
Yii
::
app
()
->
session
[
'costum'
][
"welcomeTpl"
]){
if
(
Yii
::
app
()
->
request
->
isAjaxRequest
)
echo
$controller
->
renderPartial
(
"co2.views.app.welcome"
,
array
(),
true
);
else
if
(
isset
(
Yii
::
app
()
->
session
[
'costum'
][
"welcomeTpl"
])){
$params
=
[];
if
(
isset
(
$test
)
)
$params
=
[
"tpl"
=>
$id
,
"test"
=>
$test
];
if
(
Yii
::
app
()
->
request
->
isAjaxRequest
){
echo
$controller
->
renderPartial
(
"co2.views.app.welcome"
,
$params
,
true
);
}
else
$controller
->
render
(
"co2.views.app.welcome"
/*,array( "el" => @$el )*/
);
$controller
->
render
(
"co2.views.app.welcome"
,
$params
);
}
else
...
...
models/Costum.php
View file @
24d3acc1
...
...
@@ -54,15 +54,23 @@ class Costum {
// it's the slug of an element
//$init this action can render a result for a page request
//$jsonOrDB defines if working with the data/xxxx.json file
public
static
function
init
(
$ctrl
,
$id
=
null
,
$type
=
null
,
$slug
=
null
,
$source
=
"db"
,
$test
=
null
){
public
static
function
init
(
$ctrl
,
$id
=
null
,
$type
=
null
,
$slug
=
null
,
$source
=
"db"
,
$test
=
null
,
$where
=
null
){
//$params = CO2::getThemeParams();
//Yii::app()->session['paramsConfig']=$params;
$elParams
=
[
"shortDescription"
,
"profilImageUrl"
,
"profilThumbImageUrl"
,
"profilMediumImageUrl"
,
"profilBannerUrl"
,
"name"
,
"tags"
,
"description"
,
"costum"
,
"links"
,
"profilRealBannerUrl"
];
$tmp
=
array
();
//ex : http://127.0.0.1/ph/costum/co/index/slug/cocampagne
//le slug appartient à un élément
$debug
=
false
;
if
(
$debug
){
var_dump
(
"where "
.
$where
);
var_dump
(
"id "
.
$id
);
var_dump
(
"type "
.
$type
);
var_dump
(
"slug "
.
$slug
);
//exit;
}
if
(
isset
(
$test
)
)
{
if
(
$debug
)
var_dump
(
'by test '
.
$test
);
$id
=
$test
;
$el
=
Slug
::
getElementBySlug
(
$slug
,
$elParams
);
$tmp
[
'contextType'
]
=
$el
[
"type"
];
...
...
@@ -70,6 +78,7 @@ class Costum {
}
else
if
(
isset
(
$slug
)
)
{
if
(
$debug
)
var_dump
(
'by element slug '
.
$slug
);
$el
=
Slug
::
getElementBySlug
(
$slug
,
$elParams
);
$tmp
[
'contextType'
]
=
$el
[
"type"
];
$tmp
[
'contextId'
]
=
$el
[
"id"
];
...
...
@@ -77,6 +86,7 @@ class Costum {
$id
=
(
isset
(
$el
[
"el"
][
"costum"
][
'id'
]))
?
$el
[
"el"
][
"costum"
][
'id'
]
:
$el
[
"el"
][
"costum"
][
'slug'
];
}
else
{
if
(
$debug
)
var_dump
(
'by default costum slug costumBuilder'
);
//generate the costum tag on the element with a default COstum template
//can be changed in the costum admin
...
...
@@ -88,6 +98,7 @@ class Costum {
//ex : http://127.0.0.1/ph/costum/co/index/id/xxxx/type/organizations
//l'id et le type permettent de retrouver un élément
else
if
(
isset
(
$type
)
&&
isset
(
$id
)){
if
(
$debug
)
var_dump
(
'by type and ID '
.
$id
.
" : "
.
$type
);
$el
=
array
(
"el"
=>
Element
::
getByTypeAndId
(
$type
,
$id
,
$elParams
));
$tmp
[
'contextType'
]
=
$type
;
$tmp
[
'contextId'
]
=
$id
;
...
...
@@ -101,8 +112,14 @@ class Costum {
else
$id
=
(
!
empty
(
$id
))
?
$id
:
@
$_GET
[
"id"
];
// var_dump($id);
// exit;
if
(
$debug
){
var_dump
(
'contextId : '
.
@
$tmp
[
'contextId'
]);
var_dump
(
'contextType : '
.
@
$tmp
[
'contextType'
]);
var_dump
(
'session contextId : '
.
@
Yii
::
app
()
->
session
[
'costum'
][
'contextId'
]);
var_dump
(
'session contextType : '
.
@
Yii
::
app
()
->
session
[
'costum'
][
'contextType'
]);
var_dump
(
"id "
.
$id
);
}
// exit;
if
(
!
empty
(
$id
)){
//Rest::json($id); exit ;
if
(
strlen
(
$id
)
==
24
&&
ctype_xdigit
(
$id
)
){
...
...
@@ -113,8 +130,8 @@ class Costum {
$c
=
PHDB
::
findOne
(
Costum
::
COLLECTION
,
array
(
"slug"
=>
$id
));
//Rest::json($id); exit ;
}
//var_dump($id);exit;
// var_dump($c["slug"]);exit;
//var_dump($id);exit;
// var_dump($c["slug"]);exit;
//ATTENTION : only for dev and debug purposes
//to be sure this never appears on prod
...
...
@@ -151,10 +168,11 @@ class Costum {
$c
=
PHDB
::
findOne
(
Costum
::
COLLECTION
,
array
(
"host"
=>
$_GET
[
"host"
]));
}
// var_dump($c);
// exit;
// var_dump($c);
// exit;
if
(
isset
(
$c
)
&&
!
empty
(
$c
)){
if
(
@
$c
&&
!
empty
(
$c
)){
if
(
isset
(
$c
[
"redirect"
])){
// $slug=explode(".", $_GET["el"])[1];
$redirect
=
PHDB
::
findOne
(
Costum
::
COLLECTION
,
array
(
"slug"
=>
$c
[
"redirect"
]));
...
...
@@ -162,17 +180,22 @@ class Costum {
header
(
'Location: '
.
$url
);
//Yii::app()->createUrl("/costum/co/index/id/".$redirect["slug"]));
exit
;
}
if
(
!
isset
(
$slug
)){
$el
=
Slug
::
getElementBySlug
(
$c
[
"slug"
],
$elParams
);
$slug
=
$c
[
"slug"
];
$tmp
[
'contextType'
]
=
$el
[
"type"
];
$tmp
[
'contextId'
]
=
$el
[
"id"
];
}
if
(
isset
(
$tmp
[
'contextType'
])){
$c
[
'contextType'
]
=
$tmp
[
'contextType'
];
$c
[
'contextId'
]
=
$tmp
[
'contextId'
];
}
// var_dump($c);
// exit;
// exit;
if
(
!
empty
(
$el
[
"el"
]))
{
$element
=
array
(
...
...
@@ -187,7 +210,8 @@ class Costum {
"assetsUrl"
=>
Yii
::
app
()
->
getModule
(
"costum"
)
->
getAssetsUrl
(
true
),
"url"
=>
"/costum/co/index/id/"
.
$c
[
"slug"
],
"banner"
=>
@
$el
[
"el"
][
"profilRealBannerUrl"
]
);
//var_dump($element);
// exit;
if
(
@
$el
[
"el"
][
"profilImageUrl"
]
)
$c
[
"logo"
]
=
Yii
::
app
()
->
createUrl
(
$el
[
"el"
][
"profilImageUrl"
]);
...
...
@@ -197,16 +221,17 @@ class Costum {
$c
=
array_merge
(
$c
,
$element
);
$c
[
"admins"
]
=
Element
::
getCommunityByTypeAndId
(
$el
[
"type"
],
$el
[
"id"
],
Person
::
COLLECTION
,
"isAdmin"
);
// var_dump($el["links"]); exit;
if
(
$debug
)
var_dump
(
"array_merge( c , element ) : "
.
$c
[
'contextId'
]);
// var_dump($el["links"]); exit;
//$links = (!empty($el["links"])) ? $el["links"] : null ;
$c
[
"isMember"
]
=
Link
::
isLinked
(
$el
[
"id"
],
$el
[
"type"
],
Yii
::
app
()
->
session
[
"userId"
],
@
$c
[
"communityLinks"
]);
// var_dump(Authorisation::isInterfaceAdmin()); var_dump($c["admins"]);
// var_dump(Yii::app()->session["userId"]);
// var_dump(Authorisation::isInterfaceAdmin()); var_dump($c["admins"]);
// var_dump(Yii::app()->session["userId"]);
if
(
Authorisation
::
isInterfaceAdmin
()
&&
!
isset
(
$c
[
"admins"
][
Yii
::
app
()
->
session
[
"userId"
]])){
$c
[
"admins"
][
Yii
::
app
()
->
session
[
"userId"
]]
=
array
(
"type"
=>
Person
::
COLLECTION
,
"isAdmin"
=>
true
);
}
if
(
isset
(
$c
[
"admins"
][
Yii
::
app
()
->
session
[
"userId"
]])){
// var_dump("iciiii"); exit;
// var_dump("iciiii"); exit;
Yii
::
app
()
->
session
[
'isCostumAdmin'
]
=
true
;
$c
[
"isCostumAdmin"
]
=
true
;
}
else
{
...
...
@@ -280,7 +305,7 @@ class Costum {
}
// Besoin d'approfindir ce sujet des jsons et de leurs utilisations
// Ici je l'ai utilisé pour injecter des tags spécifiques au pacte / on pourrait aussi penser au catégories d'événement
//var_dump($c["tags"]); exit;
//var_dump($c["tags"]); exit;
if
(
isset
(
$c
[
"lists"
]))
$c
=
Costum
::
getAndConvertLists
(
$c
);
if
(
isset
(
$c
[
"json"
])){
...
...
@@ -313,6 +338,9 @@ class Costum {
Yii
::
app
()
->
session
[
"paramsConfig"
]
=
Costum
::
filterThemeInCustom
(
Yii
::
app
()
->
session
[
"paramsConfig"
]);
}
if
(
$debug
)
var_dump
(
'session contextId : '
.
@
Yii
::
app
()
->
session
[
'costum'
][
'contextId'
]);
if
(
$debug
)
var_dump
(
'session contextType : '
.
@
Yii
::
app
()
->
session
[
'costum'
][
'contextType'
]);
}
//merge and update existing fields
...
...
views/common.php
View file @
24d3acc1
...
...
@@ -2,11 +2,11 @@
<script
type=
"text/javascript"
>
jQuery
(
document
).
ready
(
function
()
{
contextData
=
{
name
:
"
<?php
echo
$el
[
'name'
]
?>
"
,
type
:
"
<?php
echo
$el
[
'type'
]
?>
"
,
slug
:
"
<?php
echo
$el
[
'slug'
]
?>
"
,
typeSig
:
"
<?php
echo
$el
[
'type'
]
?>
"
,
id
:
"
<?php
echo
(
string
)
$el
[
'_id'
]
?>
"
name
:
"
<?php
echo
$el
[
'name'
]
?>
"
,
type
:
"
<?php
echo
$el
[
'type'
]
?>
"
,
slug
:
"
<?php
echo
$el
[
'slug'
]
?>
"
,
typeSig
:
"
<?php
echo
$el
[
'type'
]
?>
"
,
id
:
"
<?php
echo
(
string
)
$el
[
'_id'
]
?>
"
};
console
.
log
(
"
common contextData
"
,
contextData
);
alert
(
"
cosmon mmon
"
);
...
...
views/custom/co/campagne.php
View file @
24d3acc1
...
...
@@ -17,7 +17,10 @@ if(isset(Yii::app()->session["costum"]["contextType"]) && isset(Yii::app()->sess
array
(
"parent."
.
Yii
::
app
()
->
session
[
"costum"
][
"contextId"
]
=>
array
(
'$exists'
=>
1
),
"parent."
.
Yii
::
app
()
->
session
[
"costum"
][
"contextId"
]
.
".type"
=>
Yii
::
app
()
->
session
[
"costum"
][
"contextType"
],
"type"
=>
"cms"
)
);
}
?>
}
?>
<div>
...
...
@@ -108,12 +111,13 @@ if(isset(Yii::app()->session["costum"]["contextType"]) && isset(Yii::app()->sess
</style>
<?php
if
(
!@
$el
[
"costum"
]
&&
false
){
echo
$this
->
renderPartial
(
"costum.views.tpls.acceptAndAdmin"
,
array
(
"el"
=>
$el
,
"tpl"
=>
"campagne"
),
true
);
}
<?php
$params
=
[
"el"
=>
$el
,
"tpl"
=>
"campagne"
];
if
(
isset
(
$test
))
$params
[
"test"
]
=
"campagne"
;
echo
$this
->
renderPartial
(
"costum.views.tpls.acceptAndAdmin"
,
$params
,
true
);
?>
<div
class=
"col-xs-12 no-padding"
id=
"customHeader"
style=
"background-color: white"
>
...
...
views/custom/custom/choose.php
View file @
24d3acc1
...
...
@@ -58,7 +58,7 @@ header{
<img
src=
'
<?php
echo
$img
?>
'
class=
'img-responsive'
/>
</div>
<div
class=
'col-xs-12'
>
<a
href=
'
<?php
echo
Yii
::
app
()
->
createUrl
(
"/costum/co/index/slug/"
.
$_GET
[
"slug"
]
.
"/test/"
.
$v
[
"slug"
])
?>
'
class=
'col-xs-12 elipsis'
target=
'_blank'
>
<a
href=
'
<?php
echo
Yii
::
app
()
->
createUrl
(
"/costum/co/index/slug/"
.
@
$_GET
[
"slug"
]
.
"/test/"
.
$v
[
"slug"
])
?>
'
class=
'col-xs-12 elipsis'
target=
'_blank'
>
"
<h3>
<?php
echo
$el
[
"name"
]
?>
</h3>
</a>
<span
class=
'col-xs-12'
>
<?php
echo
@
$el
[
"shortDescription"
]
?>
</span>
...
...
views/tpls/acceptAndAdmin.php
View file @
24d3acc1
<
script
type=
"text/javascript"
>
<
?php
var
DFdata
=
{
'
tpl
'
:
'
<?php
echo
$tpl
?>
'
,
"
id
"
:
"
<?php
echo
Yii
::
app
()
->
session
[
"costum"
][
"contextId"
]
?>
"
};
costum
.
col
=
"
<?php
echo
Yii
::
app
()
->
session
[
"costum"
][
"contextType"
]
?>
"
;
costum
.
ctrl
=
"
<?php
echo
Element
::
getControlerByCollection
(
Yii
::
app
()
->
session
[
"costum"
][
"contextType"
])
?>
"
;
</script>
<div
class=
"alert alert-danger text-center"
>
<strong>
Hey!
</strong>
Is this what you want ?
Choose and configure your template
<a
href=
"javascript:;"
onclick=
"dyFObj.openForm(costum,null,DFdata ) "
class=
"btn btn-default"
>
here
</a>
</div>
\ No newline at end of file
if
(
isset
(
$test
)
||
(
Yii
::
app
()
->
session
[
'costum'
][
"dynForm"
]
&&
Authorisation
::
canEdit
(
Yii
::
app
()
->
session
[
"userId"
]
,
Yii
::
app
()
->
session
[
"costum"
][
"contextId"
],
Yii
::
app
()
->
session
[
"costum"
][
"contextType"
]
)
)
)
{
?>
<script
type=
"text/javascript"
>
var
DFdata
=
{
'
tpl
'
:
'
<?php
echo
$tpl
?>
'
,
"
id
"
:
"
<?php
echo
Yii
::
app
()
->
session
[
"costum"
][
"contextId"
]
?>
"
};
costum
.
col
=
"
<?php
echo
Yii
::
app
()
->
session
[
"costum"
][
"contextType"
]
?>
"
;
costum
.
ctrl
=
"
<?php
echo
Element
::
getControlerByCollection
(
Yii
::
app
()
->
session
[
"costum"
][
"contextType"
])
?>
"
;
function
saveThisTpl
(
slug
)
{
data
=
{
collection
:
costum
.
contextType
,
id
:
costum
.
contextId
,
path
:
"
costum.slug
"
,
value
:
'
<?php
echo
$tpl
?>
'
}
mylog
.
log
(
"
.saveThisTpl
"
,
"
data
"
,
data
);
// http://127.0.0.1/costum/co/index/slug/administration-opal/test/campagne#
dataHelper
.
path2Value
(
data
,
function
(
params
)
{
var
s
=
location
.
href
;
var
a
=
s
.
split
(
'
/
'
);
s
=
s
.
replace
(
a
[
a
.
length
-
2
]
+
'
/
'
,
''
);
s
=
s
.
replace
(
a
[
a
.
length
-
1
],
''
);
location
.
href
=
s
;
}
);
}
</script>
<div
class=
"alert alert-danger text-center"
style=
""
>
<strong>
Hey!
</strong>
Is this what you want ?
<?php
if
(
isset
(
$test
)){
?>
<a
href=
"javascript:;"
onclick=
" saveThisTpl('
<?php
echo
$tpl
?>
') "
class=
"btn btn-default"
>
First Save
</a>
<?php
}
else
if
(
Yii
::
app
()
->
session
[
'costum'
][
"dynForm"
])
{
?>
<?php
echo
Yii
::
app
()
->
session
[
"costum"
][
"contextId"
]
.
"<br/>"
?>
<?php
echo
Yii
::
app
()
->
session
[
"costum"
][
"contextType"
]
.
"<br/>"
?>
<?php
//var_dump(Yii::app()->session["costum"]) ?>
Configure
your
Costum
Template
<
a
href
=
"javascript:;"
onclick
=
"dyFObj.openForm(costum,null,DFdata ) "
class
=
"btn btn-default"
>
here
</
a
>
<?
php
}
?>
</div>
<?php
}
?>
\ No newline at end of file
Write
Preview
Supports
Markdown
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