/** * Updates text search field * @author Howard <*****@*****.**> * @static * @param int $property_id */ public static function update_text_search_field($property_id) { $property_data = wpl_property::get_property_raw_data($property_id); /** get text_search fields **/ $fields = wpl_flex::get_fields('', 1, $property_data['kind'], 'text_search', '1'); $rendered = self::render_property($property_data, $fields); $text_search_data = array(); foreach ($rendered as $data) { if (!isset($data['type'])) { continue; } if (isset($data['type']) and !trim($data['type']) or isset($data['value']) and !trim($data['value'])) { continue; } /** default value **/ $value = isset($data['value']) ? $data['value'] : ''; $value2 = ''; $type = $data['type']; if ($type == 'text' or $type == 'textarea') { $value = $data['name'] . ' ' . $data['value']; } elseif ($type == 'neighborhood') { $value = $data['name'] . (isset($data['distance']) ? ' (' . $data['distance'] . ' ' . __('MINUTES', WPL_TEXTDOMAIN) . ' ' . __('BY', WPL_TEXTDOMAIN) . ' ' . $data['by'] . ')' : ''); } elseif ($type == 'feature') { $feature_value = $data['name']; if (isset($data['values'][0])) { $feature_value .= ' '; foreach ($data['values'] as $val) { $feature_value .= $val . ', '; } $feature_value = rtrim($feature_value, ', '); } $value = $feature_value; } elseif ($type == 'locations' and isset($data['locations']) and is_array($data['locations'])) { $location_value = ''; foreach ($data['locations'] as $location_level => $value) { $location_value .= $data['keywords'][$location_level] . ' '; $abbr = wpl_locations::get_location_abbr_by_name($data['raw'][$location_level], $location_level); $name = wpl_locations::get_location_name_by_abbr($abbr, $location_level); $location_value .= $name . ' ' . ($name != $abbr ? $abbr . ' ' : NULL); } $location_value .= __('County', WPL_TEXTDOMAIN); $value = $location_value; } elseif (isset($data['value'])) { $value = $data['name'] . ' ' . $data['value']; if (is_numeric($data['value'])) { $value2 = $data['name'] . ' ' . wpl_global::number_to_word($data['value']); } } /** set value in text search data **/ if (trim($value) != '') { $text_search_data[] = strip_tags($value); } if (trim($value2) != '') { $text_search_data[] = strip_tags($value2); } } $column = 'textsearch'; if (wpl_global::check_multilingual_status()) { $column = wpl_addon_pro::get_column_lang_name($column, wpl_global::get_current_language(), false); } wpl_db::set('wpl_properties', $property_id, $column, wpl_db::escape(implode(' ', $text_search_data))); }
/** * Generate Text search field * @author Howard R <*****@*****.**> * @static * @param int $user_id */ public static function update_text_search_field($user_id) { $user_data = (array) wpl_users::get_wpl_user($user_id); /** get text_search fields **/ $fields = wpl_flex::get_fields('', 1, 2, 'text_search', '1'); $rendered = self::render_profile($user_data, $fields); $text_search_data = array(); foreach ($rendered as $data) { if (isset($data['type']) and !trim($data['type']) or isset($data['value']) and !trim($data['value'])) { continue; } /** default value **/ $value = isset($data['value']) ? $data['value'] : ''; $value2 = ''; $type = isset($data['type']) ? $data['type'] : ''; if ($type == 'text' or $type == 'textarea') { $value = $data['name'] . ' ' . $data['value']; } elseif ($type == 'locations' and isset($data['locations']) and is_array($data['locations'])) { $location_value = ''; foreach ($data['locations'] as $location_level => $value) { $location_value .= $data['keywords'][$location_level] . ' '; $abbr = wpl_locations::get_location_abbr_by_name($data['raw'][$location_level], $location_level); $name = wpl_locations::get_location_name_by_abbr($abbr, $location_level); $location_value .= $name . ' ' . ($name != $abbr ? $abbr . ' ' : NULL); } $location_value .= __('County', WPL_TEXTDOMAIN); $value = $location_value; } elseif (isset($data['value'])) { $value = $data['name'] . ' ' . $data['value']; if (is_numeric($data['value'])) { $value2 = $data['name'] . ' ' . wpl_global::number_to_word($data['value']); } } /** set value in text search data **/ $text_search_data[] = $value; if (trim($value2) != '') { $text_search_data[] = $value2; } } $column = 'textsearch'; if (wpl_global::check_multilingual_status()) { $column = wpl_addon_pro::get_column_lang_name($column, wpl_global::get_current_language(), false); } wpl_db::set('wpl_users', $user_id, $column, implode(' ', wpl_db::escape($text_search_data))); }
/** * Updates text search field * @author Howard <*****@*****.**> * @static * @param int $property_id */ public static function update_text_search_field($property_id) { $property_data = wpl_property::get_property_raw_data($property_id); $kind = wpl_property::get_property_kind($property_id); /** get text_search fields **/ $fields = wpl_flex::get_fields('', 1, $property_data['kind'], 'text_search', '1'); $rendered = self::render_property($property_data, $fields); $text_search_data = array(); foreach ($rendered as $data) { if (!isset($data['type'])) { continue; } if (isset($data['type']) and !trim($data['type']) or isset($data['value']) and !trim($data['value'])) { continue; } /** default value **/ $value = isset($data['value']) ? $data['value'] : ''; $value2 = ''; $type = $data['type']; if ($type == 'text' or $type == 'textarea') { $value = $data['name'] . ' ' . $data['value']; } elseif ($type == 'neighborhood') { $value = $data['name'] . (isset($data['distance']) ? ' (' . $data['distance'] . ' ' . __('MINUTES', WPL_TEXTDOMAIN) . ' ' . __('BY', WPL_TEXTDOMAIN) . ' ' . $data['by'] . ')' : ''); } elseif ($type == 'feature') { $feature_value = $data['name']; if (isset($data['values'][0])) { $feature_value .= ' '; foreach ($data['values'] as $val) { $feature_value .= $val . ', '; } $feature_value = rtrim($feature_value, ', '); } $value = $feature_value; } elseif ($type == 'locations' and isset($data['locations']) and is_array($data['locations'])) { $location_values = array(); foreach ($data['locations'] as $location_level => $value) { array_push($location_values, $data['keywords'][$location_level]); $abbr = wpl_locations::get_location_abbr_by_name($data['raw'][$location_level], $location_level); $name = wpl_locations::get_location_name_by_abbr($abbr, $location_level); $ex_space = explode(' ', $name); foreach ($ex_space as $value_raw) { array_push($location_values, $value_raw); } if ($name !== $abbr) { array_push($location_values, $abbr); } } /** Add all location fields to the location text search **/ $location_category = wpl_flex::get_category(NULL, " AND `kind`='{$kind}' AND `prefix`='ad'"); $location_fields = wpl_flex::get_fields($location_category->id, 1, $kind); foreach ($location_fields as $location_field) { if (!isset($rendered[$location_field->id])) { continue; } if (!trim($location_field->table_column)) { continue; } if (!isset($rendered[$location_field->id]['value']) or isset($rendered[$location_field->id]['value']) and !trim($rendered[$location_field->id]['value'])) { continue; } $ex_space = explode(' ', strip_tags($rendered[$location_field->id]['value'])); foreach ($ex_space as $value_raw) { array_push($location_values, $value_raw); } } $location_suffix_prefix = wpl_locations::get_location_suffix_prefix(); foreach ($location_suffix_prefix as $suffix_prefix) { array_push($location_values, $suffix_prefix); } $location_string = ''; $location_values = array_unique($location_values); foreach ($location_values as $location_value) { $location_string .= 'LOC-' . __($location_value, WPL_TEXTDOMAIN) . ' '; } $value = trim($location_string); } elseif (isset($data['value'])) { $value = $data['name'] . ' ' . $data['value']; if (is_numeric($data['value'])) { $value2 = $data['name'] . ' ' . wpl_global::number_to_word($data['value']); } } /** set value in text search data **/ if (trim($value) != '') { $text_search_data[] = strip_tags($value); } if (trim($value2) != '') { $text_search_data[] = strip_tags($value2); } } $column = 'textsearch'; if (wpl_global::check_multilingual_status()) { $column = wpl_addon_pro::get_column_lang_name($column, wpl_global::get_current_language(), false); } wpl_db::set('wpl_properties', $property_id, $column, wpl_db::escape(implode(' ', $text_search_data))); }