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
plugins
CiviCRM Network Groups
Commits
da19c160
Commit
da19c160
authored
Mar 13, 2019
by
Christian Wach
⚽
Browse files
Move groups markup creation to own method
parent
50968033
Changes
1
Hide whitespace changes
Inline
Side-by-side
includes/civicrm-network-groups-admin.php
View file @
da19c160
...
...
@@ -322,7 +322,7 @@ class CiviCRM_Network_Groups_Admin {
/**
*
Show
our admin settings page.
*
Render
our admin settings page.
*
* @since 0.2
*/
...
...
@@ -354,6 +354,25 @@ class CiviCRM_Network_Groups_Admin {
$level_checked
=
' checked="checked"'
;
}
// Get groups markup.
$groups_markup
=
$this
->
page_settings_groups_markup
();
// Include template file.
include
(
CIVICRM_NETWORK_GROUPS_PATH
.
'assets/templates/network-settings.php'
);
}
/**
* Build the groups list formatted as HTML.
*
* @since 0.2
*
* @return str $groups_markup The groups list formatted as HTML.
*/
public
function
page_settings_groups_markup
()
{
// Init final markup.
$groups_markup
=
''
;
...
...
@@ -370,75 +389,75 @@ class CiviCRM_Network_Groups_Admin {
$this
->
plugin
->
hooks
->
filters_add
();
// Skip if we get no synced groups.
if
(
!
empty
(
$synced_groups
)
)
{
// Init groups and checkbox arrays.
$groups
=
array
();
$checkboxes
=
array
();
// Parse synced groups and order by precedence array.
foreach
(
$network_groups
AS
$ordered_group_id
)
{
foreach
(
$synced_groups
AS
$synced_group
)
{
if
(
empty
(
$synced_groups
)
)
{
return
$groups_markup
;
}
//
Get "Groups" group ID from source string
.
$tmp
=
explode
(
'synced-group-'
,
$synced_group
[
'source'
]
);
$wp_group_id
=
isset
(
$tmp
[
1
]
)
?
absint
(
trim
(
$tmp
[
1
]
)
)
:
false
;
//
Init groups and checkbox arrays
.
$groups
=
array
(
);
$checkboxes
=
array
()
;
// Bail if there isn't one.
if
(
$wp_group_id
===
false
)
continue
;
// Parse synced groups and order by precedence array.
foreach
(
$network_groups
AS
$ordered_group_id
)
{
foreach
(
$synced_groups
AS
$synced_group
)
{
// Is it in our ordered array?
if
(
$wp_group_id
==
$ordered_group_id
)
{
$groups
[
$synced_group
[
'id'
]]
=
$synced_group
;
}
// Get "Groups" group ID from source string.
$tmp
=
explode
(
'synced-group-'
,
$synced_group
[
'source'
]
);
$wp_group_id
=
isset
(
$tmp
[
1
]
)
?
absint
(
trim
(
$tmp
[
1
]
)
)
:
false
;
}
}
// Bail if there isn't one.
if
(
$wp_group_id
===
false
)
continue
;
// Parse remaining synced groups and add if not previously added.
foreach
(
$synced_groups
AS
$synced_group
)
{
if
(
!
array_key_exists
(
$synced_group
[
'id'
],
$groups
)
)
{
// Is it in our ordered array?
if
(
$wp_group_id
==
$ordered_group_id
)
{
$groups
[
$synced_group
[
'id'
]]
=
$synced_group
;
}
}
// Open sortable list.
$checkboxes
[]
=
'<ul class="civicrm-network-groups-list">'
;
// Build checkboxes.
foreach
(
$groups
AS
$group
)
{
}
}
// Get "Groups" group ID from source string.
$tmp
=
explode
(
'synced-group-'
,
$group
[
'source'
]
);
$wp_group_id
=
isset
(
$tmp
[
1
]
)
?
absint
(
trim
(
$tmp
[
1
]
)
)
:
false
;
// Parse remaining synced groups and add if not previously added.
foreach
(
$synced_groups
AS
$synced_group
)
{
if
(
!
array_key_exists
(
$synced_group
[
'id'
],
$groups
)
)
{
$groups
[
$synced_group
[
'id'
]]
=
$synced_group
;
}
}
// Determine checkbox state.
$checked
=
''
;
if
(
$wp_group_id
!==
false
AND
in_array
(
absint
(
$wp_group_id
),
$network_groups
)
)
{
$checked
=
' checked="checked"'
;
}
// Open sortable list.
$checkboxes
[]
=
'<ul class="civicrm-network-groups-list">'
;
//
Escape group ID
.
$group_id
=
esc_attr
(
$wp_group_id
);
//
Build checkboxes
.
foreach
(
$groups
AS
$group
)
{
// Add checkbox.
$checkboxes
[]
=
'<li id="sorted-'
.
$group_id
.
'">'
.
'<input type="checkbox" class="settings-checkbox" name="cng_precedence[]" value="'
.
$group_id
.
'"'
.
$checked
.
' /> '
.
'<label class="cng_settings_label" for="cng_precedence">'
.
esc_html
(
$group
[
'title'
]
)
.
'</label>'
.
'</li>'
;
// Get "Groups" group ID from source string.
$tmp
=
explode
(
'synced-group-'
,
$group
[
'source'
]
);
$wp_group_id
=
isset
(
$tmp
[
1
]
)
?
absint
(
trim
(
$tmp
[
1
]
)
)
:
false
;
// Determine checkbox state.
$checked
=
''
;
if
(
$wp_group_id
!==
false
AND
in_array
(
absint
(
$wp_group_id
),
$network_groups
)
)
{
$checked
=
' checked="checked"'
;
}
//
Close list
.
$
checkboxes
[]
=
'</ul>'
;
//
Escape group ID
.
$
group_id
=
esc_attr
(
$wp_group_id
)
;
// Build markup.
$groups_markup
=
implode
(
"
\n
"
,
$checkboxes
);
// Add checkbox.
$checkboxes
[]
=
'<li id="sorted-'
.
$group_id
.
'">'
.
'<input type="checkbox" class="settings-checkbox" name="cng_precedence[]" value="'
.
$group_id
.
'"'
.
$checked
.
' /> '
.
'<label class="cng_settings_label" for="cng_precedence">'
.
esc_html
(
$group
[
'title'
]
)
.
'</label>'
.
'</li>'
;
}
// Include template file.
include
(
CIVICRM_NETWORK_GROUPS_PATH
.
'assets/templates/network-settings.php'
);
// Close list.
$checkboxes
[]
=
'</ul>'
;
// Build markup.
$groups_markup
=
implode
(
"
\n
"
,
$checkboxes
);
// --<
return
$groups_markup
;
}
...
...
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