static function create( $actual_val, $filter_time_period = null ) { $fv = new SDFilterValue(); $fv->text = $actual_val; if ( $fv->text == ' none' ) $fv->is_none = true; if ( $fv->text == ' other' ) $fv->is_other = true; // set other fields, if it's a date or number range if ( $filter_time_period != null ) { if ( $filter_time_period == wfMsg( 'sd_filter_month' ) ) { list( $month_str, $year ) = explode( ' ', $fv->text ); $fv->month = SDUtils::stringToMonth( $month_str ); $fv->year = $year; } else { $fv->year = $fv->text; } } else { if ( $fv->text == '' ) { // do nothing } elseif ( $fv->text { 0 } == '<' ) { $possible_number = str_replace( ',', '', trim( substr( $fv->text, 1 ) ) ); if ( is_numeric( $possible_number ) ) { $fv->upper_limit = $possible_number; $fv->is_numeric = true; } } elseif ( $fv->text { 0 } == '>' ) { $possible_number = str_replace( ',', '', trim( substr( $fv->text, 1 ) ) ); if ( is_numeric( $possible_number ) ) { $fv->lower_limit = $possible_number; $fv->is_numeric = true; } } else { $elements = explode( '-', $fv->text ); if ( count( $elements ) == 2 ) { $first_elem = str_replace( ',', '', trim( $elements[0] ) ); $second_elem = str_replace( ',', '', trim( $elements[1] ) ); if ( is_numeric( $first_elem ) && is_numeric( $second_elem ) ) { $fv->lower_limit = $first_elem; $fv->upper_limit = $second_elem; $fv->is_numeric = true; } } } } return $fv; }
static function create($actual_val, $filter = null) { $fv = new SDFilterValue(); $fv->text = str_replace('_', ' ', $actual_val); if ($fv->text == ' none') { $fv->is_none = true; } elseif ($fv->text == ' other') { $fv->is_other = true; } // set other fields, if it's a date or number range if ($filter != null && $filter->property_type == 'date') { // @TODO - this should ideally be handled via query // string arrays - and this code merged in with // date-range handling - instead of just doing string // parsing on one string. if (strpos($fv->text, ' - ') > 0) { // If there's a dash, assume it's a year range $years = explode(' - ', $fv->text); $fv->year = $years[0]; $fv->end_year = $years[1]; $fv->time_period = 'year range'; } else { $date_parts = explode(' ', $fv->text); if (count($date_parts) == 3) { list($month_str, $day_str, $year) = explode(' ', $fv->text); $fv->month = SDUtils::stringToMonth($month_str); $fv->day = str_replace(',', '', $day_str); $fv->year = $year; $fv->time_period = 'day'; } elseif (count($date_parts) == 2) { list($month_str, $year) = explode(' ', $fv->text); $fv->month = SDUtils::stringToMonth($month_str); $fv->year = $year; $fv->time_period = 'month'; } else { $fv->month = null; $fv->year = $fv->text; $fv->time_period = 'year'; } } } else { if ($fv->text == '') { // do nothing } elseif ($fv->text[0] == '<') { $possible_number = str_replace(',', '', trim(substr($fv->text, 1))); if (is_numeric($possible_number)) { $fv->upper_limit = $possible_number; $fv->is_numeric = true; } } elseif ($fv->text[0] == '>') { $possible_number = str_replace(',', '', trim(substr($fv->text, 1))); if (is_numeric($possible_number)) { $fv->lower_limit = $possible_number; $fv->is_numeric = true; } } else { $elements = explode('-', $fv->text); if (count($elements) == 2) { $first_elem = str_replace(',', '', trim($elements[0])); $second_elem = str_replace(',', '', trim($elements[1])); if (is_numeric($first_elem) && is_numeric($second_elem)) { $fv->lower_limit = $first_elem; $fv->upper_limit = $second_elem; $fv->is_numeric = true; } } } } return $fv; }