bp_ps_Fields

Setup BuddyBoss profile search fields.

Description

Source

File: bp-core/profile-search/bps-fields.php

class bp_ps_Fields
{
	private static $display = array
	(
		'text'			=> array ('contains' => 'textbox', '' => 'textbox', 'like' => 'textbox'),
		'integer'		=> array ('' => 'number', 'range' => 'range'),
		'decimal'		=> array ('' => 'textbox', 'range' => 'range'),
		'date'			=> array ('date_range' => 'date_range'),
		'location'		=> array ('distance' => 'distance', 'contains' => 'textbox', '' => 'textbox', 'like' => 'textbox'),

		'text/e'		=> array ('' => array ('selectbox', 'radio'), 'one_of' => array ('checkbox', 'multiselectbox')),
		'decimal/e'		=> array ('' => array ('selectbox', 'radio'), 'range' => 'range'),
		'set/e'			=> array ('match_any' => array ('checkbox', 'multiselectbox'), 'match_all'	=> array ('checkbox', 'multiselectbox')),
	);

	public static function get_filters ($f)
	{
		$labels = array
		(
			'contains'		=> __('contains', 'buddyboss'),
			''				=> __('is', 'buddyboss'),
			'like'			=> __('is like', 'buddyboss'),
			'range'			=> __('range', 'buddyboss'),
			'date_range'    => __('date range', 'buddyboss'),
			'distance'		=> __('distance', 'buddyboss'),
			'one_of'		=> __('is one of', 'buddyboss'),
			'match_any'		=> __('match any', 'buddyboss'),
			'match_all'		=> __('match all', 'buddyboss'),
		);
		
		$filters = array ();
		foreach ($f->filters as $filter)
			$filters[$filter] = $labels[$filter];
		return $filters;
	}

	public static function set_filters ($f)
	{
		$format = isset ($f->format)? $f->format: 'none';
		$enum = (isset ($f->options) && is_array ($f->options))? count ($f->options): 0;
		$selector = $format. ($enum? '/e': '');
		if (!isset (self::$display[$selector]))  return false;

		$f->filters = array_keys (self::$display[$selector]);
		return true;
	}

	public static function is_filter ($f, $filter)
	{
		return in_array ($filter, $f->filters);
	}

	public static function valid_filter ($f, $filter)
	{
		return in_array ($filter, $f->filters)? $filter: $f->filters[0];
	}

	public static function set_display ($f, $filter)
	{
		$format = isset ($f->format)? $f->format: 'none';
		$enum = (isset ($f->options) && is_array ($f->options))? count ($f->options): 0;
		$selector = $format. ($enum? '/e': '');
		if (!isset (self::$display[$selector][$filter]))  return false;

		$display = self::$display[$selector][$filter];
		if (is_string ($display))
		{
			$f->display = $display;
		}
		else
		{
			$default = (isset ($f->type) && in_array ($f->type, $display))? $f->type: $display[0];
			$choice = apply_filters ('bp_ps_field_display', $default, $f);
			$f->display = in_array ($choice, $display)? $choice: $default;
		}
		return true;
	}
}

Changelog

Changelog
Version Description
BuddyBoss 1.0.0 Introduced.

Methods

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.