Groups directory filter
Replace the existing groups directory patch with a filterable group listing. The resultset can be filtered by continent and group status. Change-Id: I92f6694fef4a92f3f279c0c622d0c61e082f8707
This commit is contained in:
parent
1e47259ee6
commit
08d52386f2
|
@ -7,7 +7,6 @@ project = groups_directory
|
|||
dependencies[] = leaflet_mapbox
|
||||
dependencies[] = leaflet_more_maps
|
||||
dependencies[] = page_manager
|
||||
dependencies[] = views
|
||||
dependencies[] = views_content
|
||||
features[ctools][] = page_manager:pages_default:1
|
||||
features[ctools][] = views:views_default:3.0
|
||||
|
|
|
@ -5,3 +5,181 @@
|
|||
*/
|
||||
|
||||
include_once 'groups_directory.features.inc';
|
||||
|
||||
/**
|
||||
* Implements hook_block_info()
|
||||
*/
|
||||
function groups_directory_block_info() {
|
||||
$blocks['groups_directory_filter'] = array(
|
||||
'info' => t('Filter Groups'),
|
||||
'cache' => DRUPAL_NO_CACHE,
|
||||
);
|
||||
$blocks['groups_directory_list'] = array(
|
||||
'info' => t('Groups directory list'),
|
||||
'cache' => DRUPAL_NO_CACHE,
|
||||
);
|
||||
return $blocks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_block_view().
|
||||
*/
|
||||
function groups_directory_block_view($delta='') {
|
||||
$block = array();
|
||||
switch ($delta) {
|
||||
case 'groups_directory_filter':
|
||||
$block['content'] = drupal_get_form('groups_directory_filter_form');
|
||||
$block['subject'] = t('Filter Groups');
|
||||
break;
|
||||
case 'groups_directory_list':
|
||||
$block['content'] = render(groups_directory_list());
|
||||
$block['subject'] = t('Groups');
|
||||
break;
|
||||
}
|
||||
return $block;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean array helper, defaults to check_plain filter.
|
||||
*
|
||||
* @return array Filtered array values.
|
||||
*/
|
||||
function _groups_directory_clean_array($array, $filter = 'check_plain') {
|
||||
$clean = array();
|
||||
foreach ($array as $key => $val) {
|
||||
if (is_array($val)) {
|
||||
$clean[$filter($key)] = _groups_directory_clean_array($val, $filter);
|
||||
}
|
||||
else {
|
||||
$clean[$filter($key)] = $filter($val);
|
||||
}
|
||||
}
|
||||
return $clean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get query parameters using a check_plain filter on values.
|
||||
*/
|
||||
function _groups_directory_get_query_parameters() {
|
||||
$query_params = drupal_get_query_parameters();
|
||||
return _groups_directory_clean_array($query_params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Groups directory list callback.
|
||||
*/
|
||||
function groups_directory_list() {
|
||||
$query = new EntityFieldQuery();
|
||||
$query->entityCondition('entity_type', 'node')
|
||||
->entityCondition('bundle', 'group');
|
||||
$query_params = _groups_directory_get_query_parameters();
|
||||
// filter status
|
||||
if (isset($query_params['status'])) {
|
||||
$status_official = in_array('official', $query_params['status']);
|
||||
$status_new = in_array('new', $query_params['status']);
|
||||
if (($status_official) && (!$status_new)) {
|
||||
// show official groups only
|
||||
$query->fieldCondition('field_group_status', 'value', '1', '=');
|
||||
}
|
||||
if (($status_new) && (!$status_official)) {
|
||||
// show new groups only
|
||||
$query->fieldCondition('field_group_status', 'value', '1', '!=');
|
||||
}
|
||||
}
|
||||
// filter by continent
|
||||
if (isset($query_params['c'])) {
|
||||
$query->fieldCondition('field_group_location', 'continent', (array)$query_params['c']);
|
||||
}
|
||||
|
||||
// order by title
|
||||
$query->fieldOrderBy('field_group_status', 'value', 'DESC');
|
||||
$query->propertyOrderBy('title', 'ASC');
|
||||
|
||||
$result = $query->execute();
|
||||
if (isset($result['node'])) {
|
||||
$nids = array_keys($result['node']);
|
||||
$entities = entity_load('node', $nids);
|
||||
$contents = entity_view('node', $entities, 'teaser');
|
||||
} else {
|
||||
$contents = array(
|
||||
'#type' => 'markup',
|
||||
'#markup' => '<div class="results-empty">' . t('No results found.') . '</div>',
|
||||
);
|
||||
}
|
||||
return $contents;
|
||||
}
|
||||
|
||||
/**
|
||||
* Groups filter form.
|
||||
*/
|
||||
function groups_directory_filter_form($form, &$form_state) {
|
||||
module_load_include('inc', 'field_group_location', 'field_group_lookup');
|
||||
$form['continents'] = array(
|
||||
'#type' => 'checkboxes',
|
||||
'#title' => t('By continent'),
|
||||
'#options' => _continent_get_predefined_list(),
|
||||
);
|
||||
$form['status'] = array(
|
||||
'#type' => 'checkboxes',
|
||||
'#title' => 'By status',
|
||||
'#options' => array(
|
||||
'official' => 'Official group',
|
||||
'new' => 'New group',
|
||||
),
|
||||
);
|
||||
$form['submit_search'] = array(
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Search'),
|
||||
'#submit' => array('groups_directory_filter_form_submit'),
|
||||
);
|
||||
$form['submit_clear'] = array(
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Clear filters'),
|
||||
'#submit' => array('groups_directory_filter_form_clear_filters'),
|
||||
);
|
||||
$query_params = _groups_directory_get_query_parameters();
|
||||
// set defaults for continents
|
||||
$continents = isset($query_params['c']) ? $query_params['c'] : NULL;
|
||||
if ((isset($continents)) && ((array)$continents == $continents)) {
|
||||
$form['continents']['#default_value'] = $continents;
|
||||
}
|
||||
// set defaults for status
|
||||
$status = isset($query_params['status']) ? $query_params['status'] : NULL;
|
||||
if ((isset($status)) && ((array)$status == $status)) {
|
||||
$form['status']['#default_value'] = $status;
|
||||
}
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Groups filter submit callback.
|
||||
*
|
||||
* @see groups_directory_filter_form
|
||||
*/
|
||||
function groups_directory_filter_form_submit($form, &$form_state) {
|
||||
$filter = array();
|
||||
$continents = array_filter($form_state['values']['continents']);
|
||||
foreach ($continents as $value) {
|
||||
$filter[] = 'c[]='.$value;
|
||||
}
|
||||
$status = array_filter($form_state['values']['status']);
|
||||
foreach ($status as $value) {
|
||||
$filter[] = 'status[]='.$value;
|
||||
}
|
||||
$url_params = implode('&', $filter);
|
||||
$path=$GLOBALS['base_url'].strtok($_SERVER["REQUEST_URI"],'?');
|
||||
if (!empty($url_params)) {
|
||||
$path .= '?'.$url_params;
|
||||
}
|
||||
drupal_goto($path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Groups filter clear filters callback.
|
||||
*
|
||||
* @see groups_directory_filter_form
|
||||
*/
|
||||
function groups_directory_filter_form_clear_filters($form, &$form_state) {
|
||||
$path=$GLOBALS['base_url'].strtok($_SERVER["REQUEST_URI"],'?');
|
||||
drupal_goto($path);
|
||||
}
|
|
@ -14,7 +14,7 @@ function groups_directory_default_page_manager_pages() {
|
|||
$page->name = 'groups_directory';
|
||||
$page->task = 'page';
|
||||
$page->admin_title = 'Groups Directory';
|
||||
$page->admin_description = 'A directory of groups.';
|
||||
$page->admin_description = '';
|
||||
$page->path = 'groups';
|
||||
$page->access = array();
|
||||
$page->menu = array(
|
||||
|
@ -30,9 +30,7 @@ function groups_directory_default_page_manager_pages() {
|
|||
),
|
||||
);
|
||||
$page->arguments = array();
|
||||
$page->conf = array(
|
||||
'admin_paths' => FALSE,
|
||||
);
|
||||
$page->conf = array();
|
||||
$page->default_handlers = array();
|
||||
$handler = new stdClass();
|
||||
$handler->disabled = FALSE; /* Edit this to true to make a default handler disabled initially */
|
||||
|
@ -43,9 +41,9 @@ function groups_directory_default_page_manager_pages() {
|
|||
$handler->handler = 'panel_context';
|
||||
$handler->weight = 0;
|
||||
$handler->conf = array(
|
||||
'title' => 'Groups',
|
||||
'no_blocks' => 0,
|
||||
'pipeline' => 'standard',
|
||||
'title' => 'Landing page',
|
||||
'no_blocks' => FALSE,
|
||||
'pipeline' => 'ipe',
|
||||
'body_classes_to_remove' => '',
|
||||
'body_classes_to_add' => '',
|
||||
'css_id' => '',
|
||||
|
@ -54,39 +52,33 @@ function groups_directory_default_page_manager_pages() {
|
|||
'relationships' => array(),
|
||||
);
|
||||
$display = new panels_display();
|
||||
$display->layout = 'one';
|
||||
$display->layout = 'two_33_66';
|
||||
$display->layout_settings = array();
|
||||
$display->panel_settings = array(
|
||||
'style_settings' => array(
|
||||
'default' => NULL,
|
||||
'one_main' => NULL,
|
||||
'two_33_66_top' => NULL,
|
||||
'two_33_66_first' => NULL,
|
||||
'two_33_66_second' => NULL,
|
||||
'two_33_66_bottom' => NULL,
|
||||
),
|
||||
'two_33_66_second' => array(
|
||||
'style' => '-1',
|
||||
),
|
||||
);
|
||||
$display->cache = array();
|
||||
$display->title = 'Groups';
|
||||
$display->uuid = 'd2985b74-dfbb-8c44-75c5-66561d3f51d9';
|
||||
$display->title = 'User Groups';
|
||||
$display->uuid = 'B5282991-9D90-4F58-B30F-DB4729DAE4AB';
|
||||
$display->content = array();
|
||||
$display->panels = array();
|
||||
$pane = new stdClass();
|
||||
$pane->pid = 'new-36c90f7b-8dc4-8454-ad40-eb1a8c79b542';
|
||||
$pane->panel = 'one_main';
|
||||
$pane->type = 'views';
|
||||
$pane->subtype = 'groups_map';
|
||||
$pane->pid = 'new-261DFD57-3B25-4DFE-8418-5D79026050A0';
|
||||
$pane->panel = 'two_33_66_first';
|
||||
$pane->type = 'block';
|
||||
$pane->subtype = 'groups_directory-groups_directory_filter';
|
||||
$pane->shown = TRUE;
|
||||
$pane->access = array();
|
||||
$pane->configuration = array(
|
||||
'override_pager_settings' => 0,
|
||||
'use_pager' => 1,
|
||||
'nodes_per_page' => '0',
|
||||
'pager_id' => '0',
|
||||
'offset' => '0',
|
||||
'more_link' => 0,
|
||||
'feed_icons' => 0,
|
||||
'panel_args' => 0,
|
||||
'link_to_view' => 0,
|
||||
'args' => '',
|
||||
'url' => '',
|
||||
'display' => 'default',
|
||||
'override_title' => 0,
|
||||
'override_title_text' => '',
|
||||
);
|
||||
|
@ -98,31 +90,19 @@ function groups_directory_default_page_manager_pages() {
|
|||
$pane->extras = array();
|
||||
$pane->position = 0;
|
||||
$pane->locks = array();
|
||||
$pane->uuid = '36c90f7b-8dc4-8454-ad40-eb1a8c79b542';
|
||||
$display->content['new-36c90f7b-8dc4-8454-ad40-eb1a8c79b542'] = $pane;
|
||||
$display->panels['one_main'][0] = 'new-36c90f7b-8dc4-8454-ad40-eb1a8c79b542';
|
||||
$pane->uuid = '261DFD57-3B25-4DFE-8418-5D79026050A0';
|
||||
$display->content['new-261DFD57-3B25-4DFE-8418-5D79026050A0'] = $pane;
|
||||
$display->panels['two_33_66_first'][0] = 'new-261DFD57-3B25-4DFE-8418-5D79026050A0';
|
||||
$pane = new stdClass();
|
||||
$pane->pid = 'new-a462e99c-3629-0aa4-e15f-4a84115becc7';
|
||||
$pane->panel = 'one_main';
|
||||
$pane->type = 'views';
|
||||
$pane->subtype = 'groups_groups_directory';
|
||||
$pane->pid = 'new-11F619FA-9DD0-4710-AAFF-5758ECE3FAA7';
|
||||
$pane->panel = 'two_33_66_second';
|
||||
$pane->type = 'block';
|
||||
$pane->subtype = 'groups_directory-groups_directory_list';
|
||||
$pane->shown = TRUE;
|
||||
$pane->access = array();
|
||||
$pane->configuration = array(
|
||||
'override_pager_settings' => 0,
|
||||
'use_pager' => 1,
|
||||
'nodes_per_page' => '0',
|
||||
'pager_id' => '0',
|
||||
'offset' => '0',
|
||||
'more_link' => 0,
|
||||
'feed_icons' => 0,
|
||||
'panel_args' => 0,
|
||||
'link_to_view' => 0,
|
||||
'args' => '',
|
||||
'url' => '',
|
||||
'display' => 'default',
|
||||
'override_title' => 0,
|
||||
'override_title_text' => '',
|
||||
'override_title' => 1,
|
||||
'override_title_text' => '<none>',
|
||||
);
|
||||
$pane->cache = array();
|
||||
$pane->style = array(
|
||||
|
@ -130,13 +110,13 @@ function groups_directory_default_page_manager_pages() {
|
|||
);
|
||||
$pane->css = array();
|
||||
$pane->extras = array();
|
||||
$pane->position = 1;
|
||||
$pane->position = 0;
|
||||
$pane->locks = array();
|
||||
$pane->uuid = 'a462e99c-3629-0aa4-e15f-4a84115becc7';
|
||||
$display->content['new-a462e99c-3629-0aa4-e15f-4a84115becc7'] = $pane;
|
||||
$display->panels['one_main'][1] = 'new-a462e99c-3629-0aa4-e15f-4a84115becc7';
|
||||
$pane->uuid = '11F619FA-9DD0-4710-AAFF-5758ECE3FAA7';
|
||||
$display->content['new-11F619FA-9DD0-4710-AAFF-5758ECE3FAA7'] = $pane;
|
||||
$display->panels['two_33_66_second'][0] = 'new-11F619FA-9DD0-4710-AAFF-5758ECE3FAA7';
|
||||
$display->hide_title = PANELS_TITLE_FIXED;
|
||||
$display->title_pane = '0';
|
||||
$display->title_pane = 'new-261DFD57-3B25-4DFE-8418-5D79026050A0';
|
||||
$handler->conf['display'] = $display;
|
||||
$page->default_handlers[$handler->name] = $handler;
|
||||
$pages['groups_directory'] = $page;
|
||||
|
|
|
@ -80,18 +80,6 @@ function groups_directory_views_default_views() {
|
|||
|
||||
/* Display: Content pane */
|
||||
$handler = $view->new_display('panel_pane', 'Content pane', 'panel_pane_1');
|
||||
$translatables['groups_groups_directory'] = array(
|
||||
t('Master'),
|
||||
t('more'),
|
||||
t('Apply'),
|
||||
t('Reset'),
|
||||
t('Sort by'),
|
||||
t('Asc'),
|
||||
t('Desc'),
|
||||
t('[field_group_location_1-continent]'),
|
||||
t('Content pane'),
|
||||
t('View panes'),
|
||||
);
|
||||
$export['groups_groups_directory'] = $view;
|
||||
|
||||
$view = new view();
|
||||
|
@ -119,26 +107,6 @@ function groups_directory_views_default_views() {
|
|||
$handler->display->display_options['style_options']['description_field'] = '#rendered_entity';
|
||||
$handler->display->display_options['style_options']['view_mode'] = 'teaser';
|
||||
$handler->display->display_options['style_options']['map'] = 'mapbox-warden';
|
||||
$handler->display->display_options['style_options']['icon'] = array(
|
||||
'iconUrl' => '',
|
||||
'shadowUrl' => '',
|
||||
'iconSize' => array(
|
||||
'x' => '',
|
||||
'y' => '',
|
||||
),
|
||||
'iconAnchor' => array(
|
||||
'x' => '',
|
||||
'y' => '',
|
||||
),
|
||||
'shadowAnchor' => array(
|
||||
'x' => '',
|
||||
'y' => '',
|
||||
),
|
||||
'popupAnchor' => array(
|
||||
'x' => '',
|
||||
'y' => '',
|
||||
),
|
||||
);
|
||||
/* Field: Content: Title */
|
||||
$handler->display->display_options['fields']['title']['id'] = 'title';
|
||||
$handler->display->display_options['fields']['title']['table'] = 'node';
|
||||
|
@ -166,17 +134,6 @@ function groups_directory_views_default_views() {
|
|||
|
||||
/* Display: Content pane */
|
||||
$handler = $view->new_display('panel_pane', 'Content pane', 'panel_pane_1');
|
||||
$translatables['groups_map'] = array(
|
||||
t('Master'),
|
||||
t('more'),
|
||||
t('Apply'),
|
||||
t('Reset'),
|
||||
t('Sort by'),
|
||||
t('Asc'),
|
||||
t('Desc'),
|
||||
t('Content pane'),
|
||||
t('View panes'),
|
||||
);
|
||||
$export['groups_map'] = $view;
|
||||
|
||||
return $export;
|
||||
|
|
|
@ -179,4 +179,47 @@
|
|||
display: none;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/* === Groups directory === */
|
||||
|
||||
.two-33-66 {
|
||||
@extend .container;
|
||||
.region-two-33-66-first {
|
||||
@extend .col-md-4;
|
||||
}
|
||||
.region-two-33-66-second {
|
||||
@extend .col-md-8;
|
||||
}
|
||||
}
|
||||
|
||||
.pane-groups-directory-groups-directory-filter {
|
||||
.checkbox label {
|
||||
padding-left: 0px;
|
||||
}
|
||||
}
|
||||
|
||||
.pane-groups-directory-groups-directory-list {
|
||||
.node-group {
|
||||
.user-picture {
|
||||
display: none;
|
||||
}
|
||||
h2 {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
.list-inline {
|
||||
padding-left: 0px;
|
||||
margin-left: 0px;
|
||||
}
|
||||
.links > li a,
|
||||
.links > li a:hover,
|
||||
.links > li a:focus {
|
||||
color: #8A959E;
|
||||
font-size: 12px;
|
||||
text-transform: uppercase;
|
||||
padding: 0px;
|
||||
background: none;
|
||||
line-height: 20px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue