Commit da19c160 authored by Christian Wach's avatar Christian Wach
Browse files

Move groups markup creation to own method

parent 50968033
......@@ -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;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment