From 713a02296cbdfd9aa59702adf2943bbf9fd2e943 Mon Sep 17 00:00:00 2001 From: mustela Date: Fri, 19 Apr 2013 11:57:21 -0300 Subject: [PATCH 1/4] Add operator to widget The operator was added to the widget, now you can choose between add/in http://wordpress.org/support/topic/list-view-does-not-update-correctly --- core.php | 7 +++++-- templates/checkboxes.html | 3 ++- templates/lists.html | 2 +- walkers.php | 8 +++++++- widget.html | 3 +++ widget.php | 20 +++++++++++++++++--- 6 files changed, 35 insertions(+), 8 deletions(-) diff --git a/core.php b/core.php index 7bc2a0b..2381f6a 100644 --- a/core.php +++ b/core.php @@ -7,12 +7,15 @@ function request( $request ) { if ( !isset( $_GET['qmt'] ) ) return $request; + $operator = strtoupper( $_GET['qmt_operator'] ); + foreach ( $_GET['qmt'] as $taxonomy => $terms ) { + $request['tax_query'][] = array( 'taxonomy' => $taxonomy, 'terms' => $terms, 'field' => 'term_id', - 'operator' => 'IN' + 'operator' => $operator ); } @@ -230,7 +233,7 @@ function qmt_get_query( $taxname = '' ) { global $wp_query; $qmt_query = array(); - + if ( !is_null( $wp_query->tax_query ) ) { foreach ( $wp_query->tax_query->queries as &$tax_query ) { $terms = _qmt_get_term_slugs( $tax_query ); diff --git a/templates/checkboxes.html b/templates/checkboxes.html index f544f4d..85c00ae 100644 --- a/templates/checkboxes.html +++ b/templates/checkboxes.html @@ -1,5 +1,6 @@
- {{#taxonomy}} + + {{#taxonomy}}

{{title}}

    diff --git a/templates/lists.html b/templates/lists.html index 04a079d..59aa6f7 100644 --- a/templates/lists.html +++ b/templates/lists.html @@ -1,4 +1,4 @@ -
    +
    {{#taxonomy}}

    diff --git a/walkers.php b/walkers.php index b09b721..0162e51 100644 --- a/walkers.php +++ b/walkers.php @@ -169,7 +169,13 @@ function specific_data( $term, $depth ) { class QMT_Checkboxes_Walker extends QMT_Walker { protected function set_selected_terms() { - $this->selected_terms = explode( ',', qmt_get_query( $this->taxonomy ) ); + + $terms = qmt_get_query( $this->taxonomy ); + if ( strpos( $terms, '+' ) > 0 ) + $this->selected_terms = explode( '+', $terms ); + else + $this->selected_terms = explode( ',', $terms ); + } function specific_data( $term, $depth ) { diff --git a/widget.html b/widget.html index 4e44864..838320a 100644 --- a/widget.html +++ b/widget.html @@ -2,6 +2,9 @@

    {{{mode-input}}}

    +

    {{{operator-input}}}

    + +

    {{{taxonomies-label}}}

      diff --git a/widget.php b/widget.php index 1a51c40..740e29e 100644 --- a/widget.php +++ b/widget.php @@ -6,6 +6,7 @@ class Taxonomy_Drill_Down_Widget extends scbWidget { 'title' => '', 'mode' => 'lists', 'taxonomies' => array(), + 'operator' => '' ); static function init( $file ) { @@ -77,13 +78,25 @@ function form( $instance ) { 'dropdowns' => __( 'dropdowns', 'query-multiple-taxonomies' ), ), 'text' => false, - 'desc' => __( 'Mode:', 'query-multiple-taxonomies' ), + 'desc' => __( 'Mode1:', 'query-multiple-taxonomies' ), + 'extra' => array( 'class' => 'widefat' ) + ), $instance ), + 'operator-input' => $this->input( array( + 'type' => 'select', + 'name' => 'operator', + 'values' => array( + 'AND' => __( 'And', 'query-multiple-taxonomies' ), + 'IN' => __( 'Or', 'query-multiple-taxonomies' ) + ), + 'text' => false, + 'desc' => __( 'Operator:', 'query-multiple-taxonomies' ), 'extra' => array( 'class' => 'widefat' ) ), $instance ), 'taxonomies-label' => __( 'Taxonomies:', 'query-multiple-taxonomies' ) ); + $selected_taxonomies = $instance['taxonomies']; // Start with the selected taxonomies @@ -119,7 +132,7 @@ function form( $instance ) { function content( $instance ) { extract( $instance ); - + $taxonomies = array_filter( $taxonomies, array( __CLASS__, 'test_tax' ) ); $query = qmt_get_query(); @@ -132,7 +145,7 @@ function content( $instance ) { } else { echo call_user_func( array( __CLASS__, "generate_$mode" ), $taxonomies, array( 'reset-text' => __( 'Reset', 'query-multiple-taxonomies' ), - 'reset-url' => QMT_URL::get(), + 'reset-url' => QMT_URL::get(),'operator'=>$operator ) ); } } @@ -204,6 +217,7 @@ private function generate_dropdowns( $taxonomies, $data ) { } private function generate_checkboxes( $taxonomies, $data ) { + $data = array_merge( $data, array( 'base-url' => QMT_URL::get_base(), 'submit-text' => __( 'Submit', 'query-multiple-taxonomies' ), From 53e0e2f5826c5b5213e005c732fc22ae2ef873a6 Mon Sep 17 00:00:00 2001 From: mustela Date: Fri, 19 Apr 2013 17:37:43 -0300 Subject: [PATCH 2/4] qmt_get_query "improvement" Small fixes --- core.php | 4 ++-- walkers.php | 8 +++----- widget.php | 7 ++++--- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/core.php b/core.php index 2381f6a..e6a6c40 100644 --- a/core.php +++ b/core.php @@ -229,7 +229,7 @@ function is_multitax( $taxonomies = array() ) { * * @return array( taxonomy => query ) */ -function qmt_get_query( $taxname = '' ) { +function qmt_get_query( $taxname = '', $glue = '+' ) { global $wp_query; $qmt_query = array(); @@ -246,7 +246,7 @@ function qmt_get_query( $taxname = '' ) { } foreach ( $qmt_query as &$value ) - $value = implode( '+', $value ); + $value = implode( $glue, $value ); } if ( $taxname ) { diff --git a/walkers.php b/walkers.php index 0162e51..86c61d3 100644 --- a/walkers.php +++ b/walkers.php @@ -170,11 +170,9 @@ class QMT_Checkboxes_Walker extends QMT_Walker { protected function set_selected_terms() { - $terms = qmt_get_query( $this->taxonomy ); - if ( strpos( $terms, '+' ) > 0 ) - $this->selected_terms = explode( '+', $terms ); - else - $this->selected_terms = explode( ',', $terms ); + $terms = qmt_get_query( $this->taxonomy, ','); + + $this->selected_terms = explode( ',', $terms ); } diff --git a/widget.php b/widget.php index 740e29e..923c4f2 100644 --- a/widget.php +++ b/widget.php @@ -78,14 +78,14 @@ function form( $instance ) { 'dropdowns' => __( 'dropdowns', 'query-multiple-taxonomies' ), ), 'text' => false, - 'desc' => __( 'Mode1:', 'query-multiple-taxonomies' ), + 'desc' => __( 'Mode:', 'query-multiple-taxonomies' ), 'extra' => array( 'class' => 'widefat' ) ), $instance ), 'operator-input' => $this->input( array( 'type' => 'select', 'name' => 'operator', 'values' => array( - 'AND' => __( 'And', 'query-multiple-taxonomies' ), + 'AND' => __( 'And', 'query-multiple-taxonomies' ), 'IN' => __( 'Or', 'query-multiple-taxonomies' ) ), 'text' => false, @@ -145,7 +145,8 @@ function content( $instance ) { } else { echo call_user_func( array( __CLASS__, "generate_$mode" ), $taxonomies, array( 'reset-text' => __( 'Reset', 'query-multiple-taxonomies' ), - 'reset-url' => QMT_URL::get(),'operator'=>$operator + 'reset-url' => QMT_URL::get(), + 'operator'=>$operator ) ); } } From cfc8fc5a8747d3aadc1be3001a40742fb408cca4 Mon Sep 17 00:00:00 2001 From: mustela Date: Mon, 22 Apr 2013 19:07:37 -0300 Subject: [PATCH 3/4] Label 'operator' replaced by 'Operator between terms' --- widget.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/widget.php b/widget.php index 923c4f2..ced5417 100644 --- a/widget.php +++ b/widget.php @@ -89,7 +89,7 @@ function form( $instance ) { 'IN' => __( 'Or', 'query-multiple-taxonomies' ) ), 'text' => false, - 'desc' => __( 'Operator:', 'query-multiple-taxonomies' ), + 'desc' => __( 'Operator between terms:', 'query-multiple-taxonomies' ), 'extra' => array( 'class' => 'widefat' ) ), $instance ), From 06da3b4de7ee59d55d609767916840020008d20c Mon Sep 17 00:00:00 2001 From: mustela Date: Thu, 25 Apr 2013 09:02:36 -0300 Subject: [PATCH 4/4] Added script to show/hide operator --- widget.html | 2 ++ widget.php | 17 ++++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/widget.html b/widget.html index 838320a..94cccc9 100644 --- a/widget.html +++ b/widget.html @@ -1,3 +1,5 @@ + +

      {{{title-input}}}

      {{{mode-input}}}

      diff --git a/widget.php b/widget.php index ced5417..6529774 100644 --- a/widget.php +++ b/widget.php @@ -52,6 +52,17 @@ function add_script() { $(this).sortable(); $(this).disableSelection(); }); + + $('#qmt_types').change(function(){ + console.log($('#qmt_types').val()); + if ( $('#qmt_types').val() != 'checkboxes' ) + $('.operator').parent().hide(); + else{ + $('.operator').parent().show(); + } + + }); + }); 'title', 'type' => 'text', 'desc' => __( 'Title:', 'query-multiple-taxonomies' ), - 'extra' => array( 'class' => 'widefat' ) + 'extra' => array( 'class' => 'widefat', 'id'=>'prueba' ) ), $instance ), 'mode-input' => $this->input( array( @@ -79,7 +90,7 @@ function form( $instance ) { ), 'text' => false, 'desc' => __( 'Mode:', 'query-multiple-taxonomies' ), - 'extra' => array( 'class' => 'widefat' ) + 'extra' => array( 'class' => 'widefat types', 'id'=>'qmt_types' ) ), $instance ), 'operator-input' => $this->input( array( 'type' => 'select', @@ -90,7 +101,7 @@ function form( $instance ) { ), 'text' => false, 'desc' => __( 'Operator between terms:', 'query-multiple-taxonomies' ), - 'extra' => array( 'class' => 'widefat' ) + 'extra' => array( 'class' => 'widefat operator' ) ), $instance ), 'taxonomies-label' => __( 'Taxonomies:', 'query-multiple-taxonomies' )