[1mdiff --git a/UPGRADE.txt b/UPGRADE.txt[m
[1mindex f3473ee..53643c5 100644[m
[1m--- a/UPGRADE.txt[m
[1m+++ b/UPGRADE.txt[m
[36m@@ -1,4 +1,7 @@[m
[32m+[m[32m<<<<<<< HEAD[m
# Upgrading (from Drupal 6 to 7)[m
[32m+[m[32m=======[m
[32m+[m[32m>>>>>>> aa51d12a286aa871808e3994c025e896d747a2b5[m
[m
1. **BE WARE THAT NOT ALL FUNCTIONALITY HAS BEEN PORTED!**[m
[m
[1mdiff --git a/hierarchical_select.js b/hierarchical_select.js[m
[1mindex 059fcc8..3034f87 100644[m
[1m--- a/hierarchical_select.js[m
[1m+++ b/hierarchical_select.js[m
[36m@@ -450,9 +450,22 @@[m [mDrupal.HierarchicalSelect.triggerEvents = function(hsid, updateType, settings) {[m
Drupal.HierarchicalSelect.update = function(hsid, updateType, settings) {[m
var post = $('form:has(#hierarchical-select-' + hsid +'-wrapper)', Drupal.HierarchicalSelect.context).formToArray();[m
[m
[32m+[m[32m if(Drupal.settings.exposed_form_info) {[m
[32m+[m[32m $.each(Drupal.settings.exposed_form_info, function (key, val) {[m
[32m+[m[32m var keyExists = false;[m
[32m+[m[32m $.each(post, function (keyPost, valPost) {[m
[32m+[m[32m if(valPost.name == val) {[m
[32m+[m[32m keyExists = true;[m
[32m+[m[32m }[m
[32m+[m[32m });[m
[32m+[m[32m if(keyExists == false) {[m
[32m+[m[32m post.push({'name' : key, 'value' : val});[m
[32m+[m[32m }[m
[32m+[m[32m });[m
[32m+[m[32m }[m
[32m+[m
// Pass the hierarchical_select id via POST.[m
post.push({ name : 'hsid', value : hsid });[m
[31m- [m
// If a cache system is installed, let the server know if it's running[m
// properly. If it is running properly, the server will send back additional[m
// information to maintain a lazily-loaded cache.[m
[1mdiff --git a/hierarchical_select.module b/hierarchical_select.module[m
[1mindex 731267d..146a5c4 100644[m
[1m--- a/hierarchical_select.module[m
[1m+++ b/hierarchical_select.module[m
[36m@@ -333,6 +333,10 @@[m [mfunction hierarchical_select_ajax($form, $form_state) {[m
'output' => $output, [m
// 'cache' => $cache,[m
);[m
[32m+[m[32m $commands[] = array([m
[32m+[m[32m 'command' => 'viewUpdate',[m
[32m+[m[32m 'output' => $output,[m
[32m+[m[32m );[m
$new_settings = _hs_new_setting_ajax(FALSE);[m
foreach ($new_settings as $new_setting) {[m
$commands[] = array([m
[36m@@ -376,6 +380,7 @@[m [mfunction _hs_process_shortcut_special_items($config) {[m
function _hs_process_attach_css_js($element, $hsid, &$form_state, $complete_form) {[m
// Set up Javascript and add settings specifically for the current[m
// hierarchical select.[m
[32m+[m[32m $element['#attached']['library'][] = array('system', 'ui');[m
$element['#attached']['library'][] = array('system', 'drupal.ajax');[m
$element['#attached']['library'][] = array('system', 'jquery.form');[m
$element['#attached']['library'][] = array('system', 'effects.core'); [m
[36m@@ -402,7 +407,7 @@[m [mfunction _hs_process_attach_css_js($element, $hsid, &$form_state, $complete_form[m
'HierarchicalSelect' => array([m
'settings' => array([m
"hs-$hsid" => array([m
[31m- 'animationDelay' => ($config['animation_delay'] == 0) ? (int) variable_get('hierarchical_select_animation_delay', 400) : $config['animation_delay'],[m
[32m+[m[32m 'animationDelay' => ($config['animation_delay'] == 0) ? (int) variable_get('hierarchical_select_animation_delay', 0) : $config['animation_delay'],[m
'cacheId' => $config['module'] . '_' . md5(serialize($config['params'])),[m
'renderFlatSelect' => (isset($config['render_flat_select'])) ? (int) $config['render_flat_select'] : 0,[m
'createNewItems' => (isset($config['editability']['status'])) ? (int) $config['editability']['status'] : 0,[m
[36m@@ -690,9 +695,6 @@[m [mfunction _hs_process_render_nojs($element, $config) {[m
* Hierarchical select form element type #process callback.[m
*/[m
function form_hierarchical_select_process($element, &$form_state, $complete_form) { [m
[31m- // dpm('#process');[m
[31m- // dpm($form_state);[m
[31m- //[m
// Calculations.[m
//[m
[m
[36m@@ -920,7 +922,6 @@[m [mfunction _hierarchical_select_process_get_hs_selection($element) {[m
$hs_selection = ($hs_selection != -1) ? array(end($hs_selection)) : array();[m
}[m
}[m
[31m-[m
return $hs_selection;[m
}[m
[m
[36m@@ -1094,6 +1095,16 @@[m [mfunction _hierarchical_select_process_calculate_selections(&$element, $hsid, $fo[m
// - $op == t('Cancel') (used when creating a new item or a new level)[m
// - any other submit button, e.g. the "Preview" button[m
$hs_selection = _hierarchical_select_process_get_hs_selection($element);[m
[32m+[m[32m // hack to get hs_views running[m
[32m+[m[32m if(array_key_exists($element['#name'], $form_state['values'])) {[m
[32m+[m[32m $values = $form_state['values'][$element['#name']];[m
[32m+[m[32m if( is_array($values) ) {[m
[32m+[m[32m $hs_selection[] = $form_state['values'][$element['#name']]['hierarchical_select']['selects'];[m
[32m+[m[32m } else {[m
[32m+[m[32m $hs_selection[] = check_plain($form_state['values'][$element['#name']]);[m
[32m+[m[32m }[m
[32m+[m[32m }[m
[32m+[m
if ($dropbox) {[m
$db_selection = _hierarchical_select_process_get_db_selection($element, $hsid, $form_state);[m
}[m
[36m@@ -1780,7 +1791,7 @@[m [mfunction _hierarchical_select_hierarchy_generate($config, $selection, $required,[m
[m
// Level label: set an empty level label if they've been disabled.[m
$hierarchy->lineage[$depth] = 'label_' . $depth;[m
[31m- $label = ($config['level_labels']['status']) ? t($config['level_labels']['labels'][$depth]) : '';[m
[32m+[m[32m $label = ($config['level_labels']['status'] && array_key_exists($depth, $config['level_labels']['labels'])) ? t($config['level_labels']['labels'][$depth]) : '';[m
$hierarchy->levels[$depth] = array('label_' . $depth => $label) + $hierarchy->levels[$depth] + $children;[m
[m
$hierarchy->levels[$depth] = _hierarchical_select_apply_entity_settings($hierarchy->levels[$depth], $config);[m
[1mdiff --git a/includes/views.js b/includes/views.js[m
[1mindex d5b5e3e..31ca72f 100644[m
[1m--- a/includes/views.js[m
[1m+++ b/includes/views.js[m
[36m@@ -11,19 +11,43 @@[m
* of course only work when JavaScript is enabled![m
*/[m
[m
[31m-[m
[31m-if (Drupal.jsEnabled) {[m
[31m- $(document).ready(function(){[m
[31m- $('.view-filters form').submit(function() {[m
[31m- // Remove the Hierarchical Select form build id and the form id, to[m
[31m- // prevent them from ending up in the GET URL.[m
[31m- $('#edit-hs-form-build-id').remove();[m
[31m-[m
[31m- // Prepare the hierarchical select form elements that are used as[m
[31m- // exposed filters for a GET submit.[m
[32m+[m[32m(function($){[m
[32m+[m[32m Drupal.behaviors.HierarchicalSelectTaxonomyViews = {[m
[32m+[m[32m attach: function ( context, settings ) {[m
[32m+[m[32m $('.view-filters form').bind('submit', function() {[m
$('.view-filters form')[m
.find('.hierarchical-select-wrapper')[m
.trigger('prepare-GET-submit');[m
});[m
[31m- });[m
}[m
[32m+[m[32m };[m
[32m+[m[32m Drupal.behaviors.HierarchicalSelectTaxonomyViews.getViewData = function (form, options, target) {[m
[32m+[m
[32m+[m[32m var currLink = "views/ajax?";[m
[32m+[m[32m var url = Drupal.settings.basePath + currLink + "view_name=" + options.view_name + "&view_display_id=" + options.view_display_id + "&js=1&" + $(form).serialize();[m
[32m+[m[32m $.ajax({[m
[32m+[m[32m url: url,[m
[32m+[m[32m type: "GET",[m
[32m+[m[32m success: function(response) {[m
[32m+[m[32m $(target).replaceWith(response[1].data);[m
[32m+[m[32m },[m
[32m+[m[32m error: function() {[m
[32m+[m[32m var message = Drupal.t("An error occurred at @path.", {"@path": ajax_path});[m
[32m+[m[32m alert(message);[m
[32m+[m[32m },[m
[32m+[m[32m dataType: "json"[m
[32m+[m[32m });[m
[32m+[m[32m };[m
[32m+[m[32m Drupal.behaviors.HierarchicalSelectTaxonomyViews.refreshView = function () {[m
[32m+[m
[32m+[m
[32m+[m[32m var target = ".view-id-testing_term";[m
[32m+[m[32m var form = $("#views-exposed-form-testing-term-page-1");[m
[32m+[m[32m Drupal.behaviors.HierarchicalSelectTaxonomyViews.getViewData(form, {[m
[32m+[m[32m js : 0,[m
[32m+[m[32m view_name : "testing",[m
[32m+[m[32m view_display_id : "page_1"[m
[32m+[m[32m }, target);[m
[32m+[m[32m };[m
[32m+[m
[32m+[m[32m})(jQuery);[m
[1mdiff --git a/modules/hs_taxonomy.module b/modules/hs_taxonomy.module[m
[1mindex 2fc3fb4..6b83c2d 100644[m
[1m--- a/modules/hs_taxonomy.module[m
[1m+++ b/modules/hs_taxonomy.module[m
[36m@@ -566,7 +566,7 @@[m [mfunction hs_taxonomy_hierarchical_select_params() {[m
* Implementation of hook_hierarchical_select_root_level().[m
*/[m
function hs_taxonomy_hierarchical_select_root_level($params) {[m
[31m- // TODO: support multiple parents, i.e. support "save lineage".[m
[32m+[m[32m // TODO: support multiple parents, i.e. support "save lineage".#[m
$vocabulary = taxonomy_vocabulary_load($params['vid']);[m
$terms = _hs_taxonomy_hierarchical_select_get_tree($params['vid'], 0, -1, 1);[m
[m
[36m@@ -624,7 +624,6 @@[m [mfunction hs_taxonomy_hierarchical_select_children($parent, $params) {[m
}[m
}[m
}[m
[31m-[m
return _hs_taxonomy_hierarchical_select_terms_to_options($terms);[m
}[m
[m
[36m@@ -708,7 +707,7 @@[m [mfunction hs_taxonomy_hierarchical_select_item_get_label($item, $params) {[m
}[m
[m
// Use the translated term when available![m
[31m- if (module_exists('i18ntaxonomy') && i18ntaxonomy_vocabulary($term->vid) == I18N_TAXONOMY_LOCALIZE) {[m
[32m+[m[32m if ( $term->tid !== 0 && module_exists('i18n_taxonomy') && i18n_taxonomy_vocabulary_mode($term->vid) == I18N_MODE_TRANSLATE) {[m
$labels[$item] = i18n_taxonomy_term_name($term);[m
}[m
else {[m
[36m@@ -998,6 +997,9 @@[m [mfunction theme_hs_taxonomy_formatter_lineage($variables) {[m
function _hs_taxonomy_hierarchical_select_get_tree($vid, $parent = 0, $depth = -1, $max_depth = NULL, $reset = FALSE) {[m
static $children, $parents, $terms;[m
[m
[32m+[m[32m if(!isset($vid) && empty($vid)) {[m
[32m+[m[32m throw new Exception('vid should not be empty');[m
[32m+[m[32m }[m
if ($reset) {[m
$children = $parents = $terms = array();[m
}[m
[36m@@ -1008,9 +1010,22 @@[m [mfunction _hs_taxonomy_hierarchical_select_get_tree($vid, $parent = 0, $depth = -[m
// and its children, too.[m
if (!isset($children[$vid])) {[m
$children[$vid] = array();[m
[31m-[m
// TODO Please convert this statement to the D7 database API syntax.[m
[31m- $result = db_query('SELECT t.tid, t.*, parent FROM {taxonomy_term_data} t INNER JOIN {taxonomy_term_hierarchy} h ON t.tid = h.tid WHERE t.vid = :vid ORDER BY weight, name', array(':vid' => $vid));[m
[32m+[m[32m $query = db_select('taxonomy_term_data','ttd');[m
[32m+[m[32m $query->join('taxonomy_term_hierarchy', 'tth', 'ttd.tid = tth.tid');[m
[32m+[m[32m $query->fields('ttd')[m
[32m+[m[32m ->fields('tth')[m
[32m+[m[32m ->condition('ttd.vid', $vid);[m
[32m+[m[32m global $language;[m
[32m+[m[32m $vocabulary = taxonomy_vocabulary_load($vid);[m
[32m+[m[32m if(module_exists('i18n_taxonomy') && !empty($language->language) && $vocabulary->i18n_mode === I18N_MODE_TRANSLATE ) {[m
[32m+[m[32m $query->condition('ttd.language', $language->language);[m
[32m+[m[32m }[m
[32m+[m[32m $query->orderBy('weight', 'ASC')[m
[32m+[m[32m ->orderBy('name', 'ASC');[m
[32m+[m[32m $result = $query[m
[32m+[m[32m ->execute()[m
[32m+[m[32m ->fetchAllAssoc('tid');[m
foreach ($result as $term) {[m
$children[$vid][$term->parent][] = $term->tid;[m
$parents[$vid][$term->tid][] = $term->parent;[m
[36m@@ -1096,6 +1111,9 @@[m [mfunction _hs_taxonomy_hierarchical_select_terms_to_options($terms) {[m
*/[m
function _hs_taxonomy_hierarchical_select_get_depth($vid) {[m
$depth = -99999;[m
[32m+[m[32m if(!isset($vid) && empty($vid)) {[m
[32m+[m[32m throw new Exception('vid should not be empty');[m
[32m+[m[32m }[m
$tree = _hs_taxonomy_hierarchical_select_get_tree($vid);[m
foreach ($tree as $term) {[m
if ($term->depth > $depth) {[m
[1mdiff --git a/modules/hs_taxonomy_views.info b/modules/hs_taxonomy_views.info[m
[1mindex a17c657..22846b7 100644[m
[1m--- a/modules/hs_taxonomy_views.info[m
[1m+++ b/modules/hs_taxonomy_views.info[m
[36m@@ -4,6 +4,6 @@[m [mdependencies[] = hierarchical_select[m
dependencies[] = hs_taxonomy [m
dependencies[] = views[m
package = Form Elements[m
[31m-core = 6.x[m
[32m+[m[32mcore = 7.x[m
[m
files[] = hs_taxonomy_views_handler_filter_term_node_tid.inc[m
[1mdiff --git a/modules/hs_taxonomy_views.module b/modules/hs_taxonomy_views.module[m
[1mindex 84e6680..0b51ca3 100644[m
[1m--- a/modules/hs_taxonomy_views.module[m
[1m+++ b/modules/hs_taxonomy_views.module[m
[36m@@ -44,7 +44,7 @@[m [mfunction hs_taxonomy_views_menu() {[m
/**[m
* Implementation of hook_form_alter().[m
*/[m
[31m-function hs_taxonomy_views_form_alter(&$form, $form_state, $form_id) {[m
[32m+[m[32mfunction hs_taxonomy_views_form_alter(&$form, &$form_state, $form_id) {[m
//[m
if ($form_id == 'views_ui_edit_view_form') {[m
// Add JS and CSS required for Hierarchical Select to work.[m
[36m@@ -82,6 +82,49 @@[m [mfunction hs_taxonomy_views_form_alter(&$form, $form_state, $form_id) {[m
$form['options']['expose']['operator']['#description'] = $description;[m
}[m
}[m
[32m+[m
[32m+[m[32m if( $form_id == 'views_exposed_form' ) {[m
[32m+[m[32m // Since the exposed form is a GET form, we don't want it to send a wide[m
[32m+[m[32m // variety of information.[m
[32m+[m[32m $form['form_build_id']['#access'] = FALSE;[m
[32m+[m[32m $form['form_token']['#access'] = FALSE;[m
[32m+[m[32m $form['form_id']['#access'] = FALSE;[m
[32m+[m
[32m+[m[32m // In order for Ajax to work, we need the form build info. Here we check if[m
[32m+[m[32m // #ajax has been added to any form elements, and if so, pass this info as[m
[32m+[m[32m // settings via Javascript, which get attached to the submitted form on Ajax[m
[32m+[m[32m // form submissions.[m
[32m+[m[32m foreach (element_children($form) as $key) {[m
[32m+[m[32m if (array_key_exists('#ajax', $form[$key])) {[m
[32m+[m[32m $form['#attached']['js'][] = array([m
[32m+[m[32m 'type' => 'setting',[m
[32m+[m[32m 'data' => array([m
[32m+[m[32m 'exposed_form_info' => array([m
[32m+[m[32m 'form_id' => $form['#form_id'],[m
[32m+[m[32m 'form_build_id' => $form['#build_id'],[m
[32m+[m[32m // 'form_token' => $form['#token'],[m
[32m+[m[32m ),[m
[32m+[m[32m ),[m
[32m+[m[32m );[m
[32m+[m[32m $form['#attached']['js'][] = array([m
[32m+[m[32m 'type' => 'inline',[m
[32m+[m[32m 'weight' => 100,[m
[32m+[m[32m 'data' => '(function ($) {[m
[32m+[m[32m Drupal.behaviors.ViewsExposedFormAjax = {[m
[32m+[m[32m attach: function(context, settings) {[m
[32m+[m[32m for (ajax_object in Drupal.ajax) {[m
[32m+[m[32m if (Drupal.ajax[ajax_object].options) {[m
[32m+[m[32m jQuery.extend(Drupal.ajax[ajax_object].options.data, Drupal.settings.exposed_form_info);[m
[32m+[m[32m }[m
[32m+[m[32m }[m
[32m+[m[32m }[m
[32m+[m[32m };[m
[32m+[m[32m })(jQuery);',[m
[32m+[m[32m );[m
[32m+[m[32m break;[m
[32m+[m[32m }[m
[32m+[m[32m }[m
[32m+[m[32m }[m
}[m
[m
//----------------------------------------------------------------------------[m
[36m@@ -160,32 +203,14 @@[m [mfunction hs_taxonomy_views_json($view_name, $display_id) {[m
/**[m
* Implementation of hook_views_api().[m
*/[m
[31m-function hs_taxonomy_views_api() {[m
[32m+[m[32mfunction hs_taxonomy_views_views_api() {[m
return array([m
[31m- 'api' => 2,[m
[32m+[m[32m 'api' => 3,[m
'path' => drupal_get_path('module', 'hierarchical_select') . '/modules',[m
);[m
}[m
[m
/**[m
[31m- * Implementation of hook_views_handlers().[m
[31m- */[m
[31m-function hs_taxonomy_views_handlers() {[m
[31m- return array([m
[31m- 'handlers' => array([m
[31m- // Provide a subclass of the term filter handler, to make it possible to[m
[31m- // use Hierarchical Select in Views.[m
[31m- 'hs_taxonomy_views_handler_filter_term_node_tid' => array([m
[31m- 'parent' => 'views_handler_filter_term_node_tid',[m
[31m- ),[m
[31m- 'hs_taxonomy_views_handler_filter_term_node_tid_depth' => array([m
[31m- 'parent' => 'hs_taxonomy_views_handler_filter_term_node_tid',[m
[31m- ),[m
[31m- )[m
[31m- );[m
[31m-}[m
[31m-[m
[31m-/**[m
* Implementation of hook_views_data_alter().[m
*/[m
function hs_taxonomy_views_views_data_alter(&$data) {[m
[36m@@ -214,6 +239,9 @@[m [mfunction hs_taxonomy_views_views_data_alter(&$data) {[m
),[m
);[m
[m
[32m+[m[32m// $data['taxonomy_term_data']['tid']['filter']['handler'] = 'hs_taxonomy_views_handler_filter_term_node_tid';[m
[32m+[m[32m // $data['taxonomy_term_data']['tid']['filter']['handler'] = 'foobar_handler';[m
[32m+[m
// Node view type, tid field.[m
$data['taxonomy_term_node']['tid'] = array([m
'title' => t('Term ID'),[m
[36m@@ -278,6 +306,7 @@[m [mfunction hs_taxonomy_views_config_form($form, $form_state, $view, $display_id, $[m
require_once DRUPAL_ROOT . '/' . drupal_get_path('module', 'hierarchical_select') . '/includes/common.inc';[m
[m
$filter = _hs_taxonomy_views_get_filter($view, $display_id, $filter_id);[m
[32m+[m[32m $vocabulary = taxonomy_vocabulary_machine_name_load($filter['vocabulary']);[m
[m
// Build the config ID.[m
$config_id = "taxonomy-views-$view->name-$display_id-$filter_id";[m
[36m@@ -285,19 +314,18 @@[m [mfunction hs_taxonomy_views_config_form($form, $form_state, $view, $display_id, $[m
// Add the Hierarchical Select config form.[m
$module = 'hs_taxonomy_views';[m
$params = array([m
[31m- 'optional' => (bool) $filter['expose']['optional'],[m
[32m+[m[32m 'optional' => !((bool) $filter['expose']['required']),[m
'filter_id' => $filter_id,[m
[31m- 'vid' => $filter['vid'],[m
[32m+[m[32m 'vid' => $vocabulary->vid,[m
'exclude_tid' => NULL,[m
'root_term' => NULL,[m
);[m
[31m- $vocabulary = taxonomy_vocabulary_load($params['vid']);[m
$defaults = array([m
// Enable the save_lineage setting by default if the multiple parents[m
// vocabulary option is enabled.[m
'save_lineage' => (int) ($vocabulary->hierarchy == 2),[m
'editability' => array([m
[31m- 'max_levels' => _hs_taxonomy_hierarchical_select_get_depth($filter['vid']),[m
[32m+[m[32m 'max_levels' => _hs_taxonomy_hierarchical_select_get_depth($vocabulary->vid),[m
),[m
// Use our custom callback.[m
'path' => "hs_taxonomy_views_json/$view->name/$display_id",[m
[36m@@ -317,11 +345,11 @@[m [mfunction hs_taxonomy_views_config_form($form, $form_state, $view, $display_id, $[m
'entities' => t('nodes'),[m
);[m
$max_hierarchy_depth = _hs_taxonomy_hierarchical_select_get_depth($vocabulary->vid);[m
[31m- $preview_is_required = !(bool) $filter['expose']['optional'];[m
[32m+[m[32m $preview_is_required = (bool) $filter['expose']['required'];[m
$form['hierarchical_select_config'] = hierarchical_select_common_config_form($module, $params, $config_id, $defaults, $strings, $max_hierarchy_depth, $preview_is_required);[m
[m
$form['link'] = array([m
[31m- '#markup' => l("Back to the View's display configuration", "admin/structure/views/edit/$view->name", array('fragment' => 'views-tab-' . $display_id)),[m
[32m+[m[32m '#markup' => l("Back to the View's display configuration", "admin/structure/views/view/$view->name/edit", array('fragment' => 'views-tab-' . $display_id)),[m
'#prefix' => '
',[m
'#suffix' => '
',[m
'#weight' => -5,[m
[36m@@ -398,7 +426,7 @@[m [mfunction hs_taxonomy_views_hierarchical_select_params() {[m
*/[m
function hs_taxonomy_views_hierarchical_select_root_level($params) {[m
$any_label = variable_get('views_exposed_filter_any_label', 'old_any') === 'old_any' ? '<' . t('Any') . '>' : '- ' . t('Any') . ' -';[m
[31m- $root_level = ($params['optional']) ? array(HS_TAXONOMY_VIEWS_ANY_OPTION => $any_label) : array();[m
[32m+[m[32m $root_level = (!$params['required']) ? array(HS_TAXONOMY_VIEWS_ANY_OPTION => $any_label) : array();[m
$root_level += hs_taxonomy_hierarchical_select_root_level($params);[m
return $root_level;[m
}[m
[36m@@ -444,7 +472,7 @@[m [mfunction hs_taxonomy_views_hierarchical_select_item_get_label($item, $params) {[m
function hs_taxonomy_views_hierarchical_select_entity_count($item, $params) {[m
static $count;[m
[m
[31m- $current_view = views_get_current_view();[m
[32m+[m[32m/* $current_view = views_get_current_view();[m
[m
if (!isset($count[$current_view->name][$item])) {[m
$temp_view = $current_view->clone_view();[m
[36m@@ -467,6 +495,7 @@[m [mfunction hs_taxonomy_views_hierarchical_select_entity_count($item, $params) {[m
if ($item != HS_TAXONOMY_VIEWS_ANY_OPTION) {[m
// Get an array with all tids: the tid of the currently selected term and[m
// all child terms.[m
[32m+[m[32m// print_r($item);[m
$term = taxonomy_term_load($item);[m
$tree = _hs_taxonomy_hierarchical_select_get_tree($term->vid, $term->tid);[m
$tids = array($term->tid => $term->tid);[m
[36m@@ -475,7 +504,7 @@[m [mfunction hs_taxonomy_views_hierarchical_select_entity_count($item, $params) {[m
}[m
[m
$id = 'tid_' . implode('-', $tids);[m
[31m- $temp_view->display[$display_id]->handler->override_option('filters', array([m
[32m+[m[32m/* $temp_view->display[$display_id]->handler->override_option('filters', array([m
$id => array([m
'operator' => 'or',[m
'value' => $tids,[m
[36m@@ -503,59 +532,61 @@[m [mfunction hs_taxonomy_views_hierarchical_select_entity_count($item, $params) {[m
else {[m
// Disable the default value, otherwise the option will actually[m
// filter by the default value.[m
[31m- $filter_id = $params['filter_id'];[m
[31m- $temp_view->display[$display_id]->display_options['filters'][$filter_id]['value'] = array();[m
[31m- $temp_view->display[$display_id]->handler->options['filters'][$filter_id]['value'] = array();[m
[31m- $temp_view->display['default']->display_options['filters'][$filter_id]['value'] = array();[m
[31m- $temp_view->display['default']->handler->options['filters'][$filter_id]['value'] = array();[m
[31m- }[m
[31m-[m
[32m+[m[32m // $filter_id = $params['filter_id'];[m
[32m+[m[32m // $temp_view->display[$display_id]->display_options['filters'][$filter_id]['value'] = array();[m
[32m+[m[32m // $temp_view->display[$display_id]->handler->options['filters'][$filter_id]['value'] = array();[m
[32m+[m[32m // $temp_view->display['default']->display_options['filters'][$filter_id]['value'] = array();[m
[32m+[m[32m // $temp_view->display['default']->handler->options['filters'][$filter_id]['value'] = array();[m
[32m+[m[32m // }[m
[32m+[m
[32m+[m[32m//print_r($display_id);[m
// Build the queries and collect the arguments.[m
[31m- $temp_view->build($display_id);[m
[32m+[m[32m // $temp_view->build($display_id);[m
[m
// We only need the count query. We don't care about the actual fields or[m
// order of the View.[m
[31m- $count_query = !empty($temp_view->build_info['count_query']) ? $temp_view->build_info['count_query'] : $temp_view->query->count_query;[m
[31m- $args = !empty($temp_view->build_info['query_args']) ? $temp_view->build_info['query_args'] : $temp_view->query->query_args;[m
[32m+[m[32m // $count_query = !empty($temp_view->build_info['count_query']) ? $temp_view->build_info['count_query'] : $temp_view->query->count_query;[m
[32m+[m[32m // $args = !empty($temp_view->build_info['query_args']) ? $temp_view->build_info['query_args'] : $temp_view->query->query_args;[m
[m
// Regenerate the query after we set the distinct flag for the nid field.[m
// This unfortunately doesn't work, because Views doesn't create an[m
// optimized count query when any of the fields have the distinct flag set.[m
//$temp_view->query->fields['nid']['distinct'] = TRUE;[m
[31m- //$count_query = $temp_view->query->query(TRUE);[m
[32m+[m[32m $count_query = $temp_view->query->query(TRUE);[m
[m
// Due to the above: sneak DISTINCT() in through a string replace ...[m
[31m- $count_query = str_replace("SELECT node.nid AS nid", "SELECT DISTINCT(node.nid) AS nid", $count_query);[m
[32m+[m[32m // $count_query = str_replace("SELECT node.nid AS nid", "SELECT DISTINCT(node.nid) AS nid", $count_query);[m
[m
// Filter by node type if such a filter is configured in the view.[m
[31m- if (isset($current_view->filter['type'])) {[m
[31m- $node_types = $current_view->filter['type']->value;[m
[31m- if (isset($node_types)) {[m
[31m- $values = '';[m
[31m- foreach ($node_types as $key => $value) {[m
[31m- if (empty($values)) {[m
[31m- $values = '\'' . $value . '\'';[m
[31m- }[m
[31m- else {[m
[31m- $values .= ', \'' . $value . '\'';[m
[31m- }[m
[31m- }[m
[31m-[m
[31m- // Use the same sneaky string replace trick once more.[m
[31m- $count_query = str_replace("WHERE", 'WHERE node.type IN (' . $values . ') AND', $count_query);[m
[31m- }[m
[31m- }[m
[32m+[m[32m // if (isset($current_view->filter['type'])) {[m
[32m+[m[32m // $node_types = $current_view->filter['type']->value;[m
[32m+[m[32m // if (isset($node_types)) {[m
[32m+[m[32m // $values = '';[m
[32m+[m[32m // foreach ($node_types as $key => $value) {[m
[32m+[m[32m // if (empty($values)) {[m
[32m+[m[32m // $values = '\'' . $value . '\'';[m
[32m+[m[32m // }[m
[32m+[m[32m // else {[m
[32m+[m[32m // $values .= ', \'' . $value . '\'';[m
[32m+[m[32m // }[m
[32m+[m[32m // }[m
[32m+[m
[32m+[m[32m // // Use the same sneaky string replace trick once more.[m
[32m+[m[32m // $count_query = str_replace("WHERE", 'WHERE node.type IN (' . $values . ') AND', $count_query);[m
[32m+[m[32m // }[m
[32m+[m[32m // }[m
[m
// Apply the same query transformations as view::execute() does.[m
[31m- $count_query = db_rewrite_sql($count_query, $temp_view->base_table, $temp_view->base_field, array('view' => &$temp_view));[m
[31m- $count_query = 'SELECT COUNT(*) FROM (' . $count_query . ') count_alias';[m
[32m+[m[32m // $count_query = db_rewrite_sql($count_query, $temp_view->base_table, $temp_view->base_field, array('view' => &$temp_view));[m
[32m+[m[32m // $count_query = 'SELECT COUNT(*) FROM (' . $count_query . ') count_alias';[m
[m
// Execute the count query.[m
// TODO Please convert this statement to the D7 database API syntax.[m
[31m- $count[$current_view->name][$item] = db_query($count_query, $args)->fetchField();[m
[32m+[m[32m // $count[$current_view->name][$item] = db_query($count_query, $args)->fetchField();[m
}[m
[31m-[m
[31m- return $count[$current_view->name][$item];[m
[32m+[m[32m} */[m
[32m+[m[32m return 1;[m
[32m+[m[32m // return $count[$current_view->name][$item];[m
}[m
[m
/**[m
[1mdiff --git a/modules/hs_taxonomy_views_handler_filter_term_node_tid.inc b/modules/hs_taxonomy_views_handler_filter_term_node_tid.inc[m
[1mindex 1f1a4c6..ddd1047 100644[m
[1m--- a/modules/hs_taxonomy_views_handler_filter_term_node_tid.inc[m
[1m+++ b/modules/hs_taxonomy_views_handler_filter_term_node_tid.inc[m
[36m@@ -8,9 +8,27 @@[m
[m
class hs_taxonomy_views_handler_filter_term_node_tid extends views_handler_filter_term_node_tid {[m
[m
[31m- function init(&$view, $options) {[m
[32m+[m[32m function init(&$view, &$options) {[m
parent::init($view, $options);[m
[31m-[m
[32m+[m[32m // @TODO Support non exposed filters[m
[32m+[m[32m $vocabulary = taxonomy_vocabulary_machine_name_load($this->options['vocabulary']);[m
[32m+[m[32m if( array_key_exists($options['expose']['identifier'], $_GET) ) {[m
[32m+[m[32m $parent_term = $_GET[$options['expose']['identifier']];[m
[32m+[m[32m $term = taxonomy_term_load($parent_term);[m
[32m+[m[32m $tids = array();[m
[32m+[m[32m if(!$parent_term) {[m
[32m+[m[32m $tree = taxonomy_get_tree($vocabulary->vid);[m
[32m+[m[32m } else {[m
[32m+[m[32m $tree = _hs_taxonomy_hierarchical_select_get_tree($vocabulary->vid, $term->tid);[m
[32m+[m[32m $tids = array($term->tid => $term->tid);[m
[32m+[m[32m }[m
[32m+[m[32m foreach ($tree as $descendant) {[m
[32m+[m[32m $tids[$descendant->tid] = $descendant->tid;[m
[32m+[m[32m }[m
[32m+[m[32m $this->value[] = $tids;[m
[32m+[m[32m } else {[m
[32m+[m[32m $this->value = array();[m
[32m+[m[32m }[m
// The following code should logically be wrapped in a[m
// $this->select_type_is_hierarchical_select()[m
// check. However, if we'd do this, you wouldn't be able to dynamically[m
[36m@@ -23,17 +41,37 @@[m [mclass hs_taxonomy_views_handler_filter_term_node_tid extends views_handler_filte[m
// code below in such a check.[m
[m
// Add JS and CSS required for Hierarchical Select to work.[m
[31m- _hierarchical_select_setup_js();[m
[32m+[m[32m // @TODO uncomment[m
[32m+[m[32m// _hierarchical_select_setup_js();[m
[m
// Ensure that Drupal.HierarchicalSelect.prepareGETSubmit() gets called.[m
require_once DRUPAL_ROOT . '/' . drupal_get_path('module', 'hierarchical_select') . '/includes/common.inc';[m
[31m- hierarchical_select_common_add_views_js();[m
[32m+[m[32m // @TODO uncomment[m
[32m+[m[32m// hierarchical_select_common_add_views_js();[m
}[m
[m
function value_form(&$form, &$form_state) {[m
// Support limiting of vocabulary by the vocabulary's module name (this is[m
// possible when a vocabulary is exported/defined as a feature, see[m
// http://drupal.org/node/789556) or by the vocabulary's vid.[m
[32m+[m[32m// if( array_key_exists($this->options['relationship'], $form_state['input']) ) {[m
[32m+[m[32m// $parent_term = $form_state['input'][$this->options['relationship']];[m
[32m+[m[32m// $term = taxonomy_term_load($parent_term);[m
[32m+[m[32m// $vocabulary = taxonomy_vocabulary_machine_name_load($this->options['vocabulary']);[m
[32m+[m[32m// $tids = array();[m
[32m+[m[32m// if(!$parent_term) {[m
[32m+[m[32m// $tree = taxonomy_get_tree($vocabulary->vid);[m
[32m+[m[32m// } else {[m
[32m+[m[32m// $tree = _hs_taxonomy_hierarchical_select_get_tree($vocabulary->vid, $term->tid);[m
[32m+[m[32m// $tids = array($term->tid => $term->tid);[m
[32m+[m[32m// }[m
[32m+[m[32m// foreach ($tree as $descendant) {[m
[32m+[m[32m// $tids[$descendant->tid] = $descendant->tid;[m
[32m+[m[32m// }[m
[32m+[m[32m// $this->value[] = $tids;[m
[32m+[m[32m// } else {[m
[32m+[m[32m// $this->value = array();[m
[32m+[m[32m// }[m
if (isset($this->options['limit_by']) && $this->options['limit_by'] == 'module') {[m
foreach (taxonomy_get_vocabularies() as $vid => $vocab) {[m
if ($vocab->module == $this->options['module']) {[m
[36m@@ -43,29 +81,27 @@[m [mclass hs_taxonomy_views_handler_filter_term_node_tid extends views_handler_filte[m
}[m
}[m
else {[m
[31m- $vocabulary = taxonomy_vocabulary_load($this->options['vid']);[m
[32m+[m[32m $vocabulary = taxonomy_vocabulary_machine_name_load($this->options['vocabulary']);[m
}[m
[m
$view_name = $this->view->name;[m
$filter_id = $this->options['id'];[m
$display_id = _hs_taxonomy_views_get_display_id_for_filter($this->view, $filter_id);[m
[31m- $optional = $this->options['expose']['optional'];[m
[32m+[m[32m $required = $this->options['expose']['required'];[m
[m
$config_id = "taxonomy-views-$view_name-$display_id-$filter_id";[m
[m
[31m- // When not exposed: settings form.[m
[31m- if (empty($form_state['exposed'])) {[m
[31m- // When the 'Selection type' is 'Hierarchical Select', user our own[m
[31m- // value_form, otherwise use the parent's class form.[m
[31m- if ($this->options['type'] == 'textfield' || $this->options['type'] == 'select') {[m
[32m+[m[32m // When the 'Selection Type' isn't 'Hierachical Select' use[m
[32m+[m[32m // parent's form.[m
[32m+[m[32m if (!$this->select_type_is_hierarchical_select()) {[m
parent::value_form($form, $form_state);[m
[31m- }[m
[31m- else {[m
[32m+[m[32m } else {[m
[32m+[m[32m if ( ! $this->is_exposed() ) {[m
$config = hierarchical_select_common_config_get($config_id);[m
$form['value'] = array([m
'#type' => 'hierarchical_select',[m
'#title' => t('Select terms from vocabulary @voc', array('@voc' => $vocabulary->name)),[m
[31m- '#default_value' => !empty($this->value) ? $this->value : array(),[m
[32m+[m[32m '#default_value' => $this->value,[m
'#config' => array([m
'module' => 'hs_taxonomy',[m
'params' => array([m
[36m@@ -95,27 +131,23 @@[m [mclass hs_taxonomy_views_handler_filter_term_node_tid extends views_handler_filte[m
),[m
);[m
}[m
[31m- }[m
// When exposed: filter form.[m
else {[m
[31m- // When the 'Selection type' is 'Hierarchical Select', user our own[m
[31m- // value_form, otherwise use the parent's class form.[m
[31m- if (!$this->select_type_is_hierarchical_select()) {[m
[31m- parent::value_form($form, $form_state);[m
[31m- }[m
[31m- else {[m
[32m+[m[32m drupal_add_js(drupal_get_path('module', 'hierarchical_select').'/includes/views.js');[m
$default_value = (isset($this->value) && !empty($this->value)) ? $this->value : array();[m
[m
// Basic settings for the form item.[m
$form['value']['#type'] = 'hierarchical_select';[m
$form['value']['#default_value'] = $default_value;[m
[31m- $form['value']['#required'] = !((bool) $optional);[m
[32m+[m[32m $form['value']['#required'] = ((bool) $required);[m
[32m+[m
[32m+[m[32m $form['value']['#ajax'] = NULL;[m
[m
// Apply the Hierarchical Select configuration to the form item.[m
$defaults_override = array([m
'module' => 'hs_taxonomy_views',[m
'params' => array([m
[31m- 'optional' => (bool) $optional,[m
[32m+[m[32m 'required' => !((bool) $required),[m
'filter_id' => $filter_id,[m
'vid' => $vocabulary->vid,[m
'exclude_tid' => NULL,[m
[36m@@ -150,15 +182,11 @@[m [mclass hs_taxonomy_views_handler_filter_term_node_tid extends views_handler_filte[m
function extra_options_form(&$form, &$form_state) {[m
parent::extra_options_form($form, $form_state);[m
[m
[31m- $form['type'] = array([m
[31m- '#type' => 'radios',[m
[31m- '#title' => t('Selection type'),[m
[31m- '#options' => array([m
[31m- 'select' => t('Dropdown'),[m
[31m- 'textfield' => t('Autocomplete'),[m
[31m- 'hierarchical_select' => t('Hierarchical Select'),[m
[31m- ),[m
[31m- '#default_value' => $this->options['type'],[m
[32m+[m[32m $form['type']['#options'] = array_merge([m
[32m+[m[32m $form['type']['#options'],[m
[32m+[m[32m array([m
[32m+[m[32m 'hierarchical_select' => t('Hierarchical Select')[m
[32m+[m[32m )[m
);[m
[m
$filter_id = $form_state['id'];[m
[36m@@ -168,7 +196,7 @@[m [mclass hs_taxonomy_views_handler_filter_term_node_tid extends views_handler_filte[m
'#markup' => l(t('Configure Hierarchical Select'), _hs_taxonomy_views_config_path($this->view->name, $display_id, $filter_id)),[m
'#suffix' => '',[m
// Doesn't work because #process is not called for #type = markup form items.[m
[31m- '#process' => array('views_process_dependency'),[m
[32m+[m[32m '#process' => array('ctools_dependent_process'),[m
'#dependency' => array('radio:options[type]' => array('hierarchical_select')),[m
// Set #input = TRUE so that #process will be called.[m
'#input' => TRUE,[m
[36m@@ -234,7 +262,7 @@[m [mclass hs_taxonomy_views_handler_filter_term_node_tid extends views_handler_filte[m
}[m
[m
function admin_summary() {[m
[31m- $this->value = (array) $this->value;[m
[32m+[m[32m $this->value = NULL;[m
return parent::admin_summary();[m
}[m
[m
[1mdiff --git a/modules/hs_taxonomy_views_handler_filter_term_node_tid_depth.inc b/modules/hs_taxonomy_views_handler_filter_term_node_tid_depth.inc[m
[1mnew file mode 100644[m
[1mindex 0000000..0bafd13[m
[1m--- /dev/null[m
[1m+++ b/modules/hs_taxonomy_views_handler_filter_term_node_tid_depth.inc[m
[36m@@ -0,0 +1,90 @@[m
[32m+[m[32m t('Is one of'),[m
[32m+[m[32m );[m
[32m+[m[32m }[m
[32m+[m
[32m+[m[32m function option_definition() {[m
[32m+[m[32m $options = parent::option_definition();[m
[32m+[m
[32m+[m[32m $options['depth'] = array('default' => 0);[m
[32m+[m
[32m+[m[32m return $options;[m
[32m+[m[32m }[m
[32m+[m
[32m+[m[32m function extra_options_form(&$form, &$form_state) {[m
[32m+[m[32m parent::extra_options_form($form, $form_state);[m
[32m+[m
[32m+[m[32m $form['depth'] = array([m
[32m+[m[32m '#type' => 'weight',[m
[32m+[m[32m '#title' => t('Depth'),[m
[32m+[m[32m '#default_value' => $this->options['depth'],[m
[32m+[m[32m '#description' => t('The depth will match nodes tagged with terms in the hierarchy. For example, if you have the term "fruit" and a child term "apple", with a depth of 1 (or higher) then filtering for the term "fruit" will get nodes that are tagged with "apple" as well as "fruit". If negative, the reverse is true; searching for "apple" will also pick up nodes tagged with "fruit" if depth is -1 (or lower).'),[m
[32m+[m[32m );[m
[32m+[m[32m }[m
[32m+[m
[32m+[m[32m function query() {[m
[32m+[m[32m // If no filter values are present, then do nothing.[m
[32m+[m[32m if (count($this->value) == 0) {[m
[32m+[m[32m return;[m
[32m+[m[32m }[m
[32m+[m[32m else if (count($this->value) == 1) {[m
[32m+[m[32m $placeholder = " = %d";[m
[32m+[m[32m }[m
[32m+[m[32m else {[m
[32m+[m[32m $placeholder = " IN (" . implode(', ', array_fill(0, sizeof($this->value), '%d')) . ")";[m
[32m+[m[32m }[m
[32m+[m
[32m+[m[32m // The normal use of ensure_my_table() here breaks Views.[m
[32m+[m[32m // So instead we trick the filter into using the alias of the base table.[m
[32m+[m[32m // See http://drupal.org/node/271833[m
[32m+[m[32m // If a relationship is set, we must use the alias it provides.[m
[32m+[m[32m if (!empty($this->relationship)) {[m
[32m+[m[32m $this->table_alias = $this->relationship;[m
[32m+[m[32m }[m
[32m+[m[32m // If no relationship, then use the alias of the base table.[m
[32m+[m[32m else if (isset($this->query->table_queue[$this->query->base_table]['alias'])) {[m
[32m+[m[32m $this->table_alias = $this->query->table_queue[$this->query->base_table]['alias'];[m
[32m+[m[32m }[m
[32m+[m[32m // This should never happen, but if it does, we fail quietly.[m
[32m+[m[32m else {[m
[32m+[m[32m return;[m
[32m+[m[32m }[m
[32m+[m
[32m+[m[32m // Now build the subqueries.[m
[32m+[m[32m $subquery = "\n SELECT tn.vid FROM {term_node} tn\n";[m
[32m+[m[32m $where = " WHERE tn.tid $placeholder\n";[m
[32m+[m[32m $args = $this->value;[m
[32m+[m[32m $last = "tn";[m
[32m+[m
[32m+[m[32m if ($this->options['depth'] > 0) {[m
[32m+[m[32m $subquery .= " LEFT JOIN {term_hierarchy} th ON th.tid = tn.tid\n";[m
[32m+[m[32m $last = "th";[m
[32m+[m[32m foreach (range(1, abs($this->options['depth'])) as $count) {[m
[32m+[m[32m $subquery .= " LEFT JOIN {term_hierarchy} th$count ON $last.parent = th$count.tid\n";[m
[32m+[m[32m $where .= " OR th$count.tid $placeholder\n";[m
[32m+[m[32m $args = array_merge($args, $this->value);[m
[32m+[m[32m $last = "th$count";[m
[32m+[m[32m }[m
[32m+[m[32m }[m
[32m+[m[32m else if ($this->options['depth'] < 0) {[m
[32m+[m[32m foreach (range(1, abs($this->options['depth'])) as $count) {[m
[32m+[m[32m $subquery .= " LEFT JOIN {term_hierarchy} th$count ON $last.tid = th$count.parent\n";[m
[32m+[m[32m $where .= " OR th$count.tid $placeholder\n";[m
[32m+[m[32m $args = array_merge($args, $this->value);[m
[32m+[m[32m $last = "th$count";[m
[32m+[m[32m }[m
[32m+[m[32m }[m
[32m+[m
[32m+[m[32m $this->query->add_where(0, "$this->table_alias.$this->real_field IN ($subquery$where )", $args);[m
[32m+[m[32m }[m
[32m+[m[32m}[m