Date Range

BP Profile Search › Date Range

  • Author
    Post
  • #8455 Reply
    Yeon
    Guest

    Dear Andrea,

    Since you told me, that you dont have much time at the moment, I thought I could digg into the code and maybe solve some problems for you 🙂

    I think i try to extent the case-switch function of bps-xprofile.php

    	switch ($filter)
    	{
    	case 'range':
    		$min = $f->min;
    		$max = $f->max;
    
    		if ($min !== '')  $sql['where']['min'] = $wpdb->prepare ("value >= %f", $min);
    		if ($max !== '')  $sql['where']['max'] = $wpdb->prepare ("value <= %f", $max);
    		break;
    
    	case 'age_range':
    		$min = $f->min;
    		$max = $f->max;
    		$time = time ();
    		$day = date ("j", $time);
    		$month = date ("n", $time);
    		$year = date ("Y", $time);
    		$ymin = $year - $max - 1;
    		$ymax = $year - $min;
    
    		if ($max !== '')  $sql['where']['age_min'] = $wpdb->prepare ("DATE(value) > %s", "$ymin-$month-$day");
    		if ($min !== '')  $sql['where']['age_max'] = $wpdb->prepare ("DATE(value) <= %s", "$ymax-$month-$day");
    		break;

    Perhaps I could implement a new case “date_range”. I will start tonight and just created this post to inform you.
    I’m gonna post any updates here…

    Cheers

    #8456 Reply
    andrea
    Plugin Author

    Good idea, go ahead!

    #8491 Reply
    Yeon
    Guest

    Dear Andrea,
    after I needed to recreate some things Im almost ready with my customized search. I got everything implemented 🙂
    Including:
    – IonRange Slider for range search
    – Conditional Profile Fields (including member type)
    – Remember both states (sliders&conditionals) [for refining search]
    – JS-Datepicker for date fields [firefox, safari,…]
    – Modded “AutoLink” in Profile to perform a “range” search when clicked on Age instead of the exact birthdate

    I don’t know, if you remember me, we once worked via teamviewer together 🙂 You said you need some time to think about.

    Now there are only 2 things left:
    The important must-have one would be the date-range-search.
    The nice-2-have one would be the clear-search-button on field_level:
    “clear this value” instead of “clear all”

    Sadly I cant get the date-range-search to work on my own 🙁
    Perhaps you have a little time? <3

    Thank you soo much for everything!! Without you I wouldn’t have come this far !!!

    Cheers
    Blade

    #8493 Reply
    andrea
    Plugin Author

    Hi Yeon,

    You have accomplished a lot!

    I’ll try to add the Date Range search, but I won’t be able to start before two or three weeks.

    Re the Clear button on each field, you can replace the current filters template with a form template of your choice. Then you can modify that form template adding all the Clear buttons, and possibly changing its look according to your preferences.

    Congratulations on all the work done so far!

    #8496 Reply
    Yeon
    Guest

    Thank you andrea!!

    I managed to inject the clear buttons:

    I edited bps-filters.php
    But I need to define the actions. At this moment every clear button clears all. Here is my bps-filters.php

    <?php
    
    /*
     * BP Profile Search - filters template 'bps-filters'
     *
     * See http://dontdream.it/bp-profile-search/form-templates/ if you wish to modify this template or develop a new one.
     *
     */
    
    	$F = bps_escaped_filters_data ();
    	$filters = '';
    
    	foreach ($F->fields as $f)
    	{
    		switch ($f->display)
    		{
    		case 'range':
    			if ($f->min === '' && $f->max === '')  break;
    			$filters .= "<strong>$f->label:</strong>";
    			if ($f->min !== '')
    				$filters .= " <strong>". __('min', 'bp-profile-search'). "</strong> $f->min";
    			if ($f->max !== '')
    				$filters .= " <strong>". __('max', 'bp-profile-search'). "</strong> $f->max";
    			/* $filters .= "<br>\n"; */
    			$filters .= "<a href='$action'>". __('Clear', 'buddypress'). "</a><br>\n";
    			break;
    
    		case 'hidden':
    			break;
    
    		case 'textbox':
    		case 'number':
    		case 'textarea':
    		case 'url':
    			if ($f->value === '')  break;
    			/* $filters .= "<strong>$f->label:</strong> $f->value<br>\n"; */
    			$filters .= "<strong>$f->label:</strong> $f->value<a href='$action'>". __('Clear', 'buddypress'). "</a><br>\n";
    			break;
    
    		case 'selectbox':
    		case 'radio':
    		case 'multiselectbox':
    		case 'checkbox':
    			$values = array ();
    			foreach ($f->options as $key => $label)
    				if (in_array ($key, $f->values))  $values[] = $label;
    			$values = implode (', ', $values);
    			if ($values === '')  break;
    			/* $filters .= "<strong>$f->label:</strong> $values<br>\n"; */
    			$filters .= "<strong>$f->label:</strong> $values<a href='$action'>". __('Clear', 'buddypress'). "</a><br>\n";
    			break;
    
    		default:
    			$filters .= "<p>BP Profile Search: don't know how to display the <em>$f->display</em> filter type.</p>\n";
    			break;
    		}
    	}
    
    	if ($filters)
    	{
    		$action = parse_url ($_SERVER['REQUEST_URI'], PHP_URL_PATH);
    
    		echo "<p class='bps_filters'>\n";
    		echo $filters;
    		echo "<a href='$action'>". __('Clear', 'buddypress'). "</a><br>\n";
    		echo "</p>\n";
    	}
    
    // BP Profile Search - end of template
    

    I think i have to modify the
    $action = parse_url ($_SERVER['REQUEST_URI'], for each button.
    You have a tip for the action to only remove the proper value?

    Gratefully

    Blade

    P.S.:
    Doesn’t care how long you take for the date-range, I will always be happy 🙂

Reply to: Date Range
My Information