static function load( $filter_name ) { $f = new SDFilter(); $f->name = $filter_name; $properties_used = SDUtils::getValuesForProperty( $filter_name, SD_NS_FILTER, '_SD_CP', SD_SP_COVERS_PROPERTY, SMW_NS_PROPERTY ); if ( count( $properties_used ) > 0 ) { $f->property = $properties_used[0]; $f->escaped_property = str_replace( array( ' ', "'" ), array( '_', "\'" ), $f->property ); } $f->is_relation = true; $proptitle = Title::newFromText( $f->property, SMW_NS_PROPERTY ); if ( $proptitle != null ) { $store = smwfGetStore(); if ( class_exists( 'SMWDIProperty' ) ) { // SMW 1.6 $propPage = new SMWDIWikiPage( $f->escaped_property, SMW_NS_PROPERTY, null ); $types = $store->getPropertyValues( $propPage, new SMWDIProperty( '_TYPE' ) ); } elseif ( class_exists( 'SMWPropertyValue' ) ) { $types = $store->getPropertyValues( $proptitle, SMWPropertyValue::makeUserProperty( 'Has type' ) ); } else { $types = $store->getSpecialValues( $proptitle, SMW_SP_HAS_TYPE ); } global $smwgContLang; $datatypeLabels = $smwgContLang->getDatatypeLabels(); if ( count( $types ) > 0 ) { if ( $types[0] instanceof SMWDIWikiPage ) { // SMW 1.6 $typeValue = $types[0]->getDBkey(); } elseif ( $types[0] instanceof SMWDIURI ) { // A bit inefficient, but it's the // simplest approach. $typeID = $types[0]->getFragment(); $typeValue = $datatypeLabels[$typeID]; } else { $typeValue = $types[0]->getWikiValue(); } if ( $typeValue != $datatypeLabels['_wpg'] ) { $f->is_relation = false; } if ( $typeValue == $datatypeLabels['_boo'] ) { $f->is_boolean = true; } if ( $typeValue == $datatypeLabels['_dat'] ) { $f->is_date = true; } } } $categories = SDUtils::getValuesForProperty( $filter_name, SD_NS_FILTER, '_SD_VC', SD_SP_GETS_VALUES_FROM_CATEGORY, NS_CATEGORY ); $time_periods = SDUtils::getValuesForProperty( $filter_name, SD_NS_FILTER, '_SD_TP', SD_SP_USES_TIME_PERIOD, null ); if ( count( $categories ) > 0 ) { $f->category = $categories[0]; $f->allowed_values = SDUtils::getCategoryChildren( $f->category, false, 5 ); } elseif ( count( $time_periods ) > 0 ) { $f->time_period = $time_periods[0]; $f->allowed_values = array(); } elseif ( $f->is_boolean ) { $f->allowed_values = array( '0', '1' ); } else { $values = SDUtils::getValuesForProperty( $filter_name, SD_NS_FILTER, '_SD_V', SD_SP_HAS_VALUE, null ); $f->allowed_values = $values; } $input_types = SDUtils::getValuesForProperty( $filter_name, SD_NS_FILTER, '_SD_IT', SD_SP_HAS_INPUT_TYPE, null ); if ( count( $input_types ) > 0 ) { $f->input_type = $input_types[0]; } // set list of possible applied filters if allowed values // array was set foreach ( $f->allowed_values as $allowed_value ) { $f->possible_applied_filters[] = SDAppliedFilter::create( $f, $allowed_value ); } return $f; }
/** * Print the line showing 'AND' values for a filter that has not * been applied to the drilldown */ function printUnappliedFilterLine($f, $cur_url) { global $sdgScriptPath; global $sdgFiltersSmallestFontSize, $sdgFiltersLargestFontSize; $f->createTempTable(); $found_results_for_filter = false; if (count($f->allowed_values) == 0) { $filter_values = $f->getAllValues(); if (count($filter_values) > 0) { $found_results_for_filter = true; } } else { $filter_values = array(); foreach ($f->allowed_values as $value) { $new_filter = SDAppliedFilter::create($f, $value); $num_results = $this->getNumResults($this->subcategory, $this->all_subcategories, $new_filter); if ($num_results > 0) { $filter_values[$value] = $num_results; } } } // now get values for 'Other' and 'None', as well // - don't show 'Other' if filter values were // obtained dynamically if (count($f->allowed_values) > 0) { $other_filter = SDAppliedFilter::create($f, ' other'); $num_results = $this->getNumResults($this->subcategory, $this->all_subcategories, $other_filter); if ($num_results > 0) { $filter_values['_other'] = $num_results; } } // show 'None' only if any other results have been found, and // if it's not a numeric filter if (count($f->allowed_values) > 0) { $fv = SDFilterValue::create($f->allowed_values[0]); if (!$fv->is_numeric) { $none_filter = SDAppliedFilter::create($f, ' none'); $num_results = $this->getNumResults($this->subcategory, $this->all_subcategories, $none_filter); if ($num_results > 0) { $filter_values['_none'] = $num_results; } } } $filter_name = urlencode(str_replace(' ', '_', $f->name)); $normal_filter = true; if (count($filter_values) == 0) { $results_line = '(' . wfMsg('sd_browsedata_novalues') . ')'; // for backward compatibility, also check against // 'sd_filter_freetext' (i.e. 'text' in English), which was // the old name of the input } elseif ($f->input_type == wfMsgForContent('sd_filter_combobox') || $f->input_type == wfMsgForContent('sd_filter_freetext')) { $results_line = $this->printComboBoxInput($filter_name, $filter_values); $normal_filter = false; } elseif ($f->input_type == wfMsgForContent('sd_filter_daterange')) { $results_line = $this->printDateRangeInput($filter_name); $normal_filter = false; } else { $results_line = $this->printUnappliedFilterValues($cur_url, $f, $filter_values); } $text = ""; $filter_label = $this->printFilterLabel($f->name); $results_div_id = strtolower(str_replace(' ', '_', $filter_label)) . "_values"; $text .= <<<END \t\t\t\t\t<div class="drilldown-filter-label"> END; // no point showing "minimize" arrow if it's just a // single text or date input if ($normal_filter) { $text .= <<<END \t\t\t\t\t<a onclick="toggleFilterDiv('{$results_div_id}', this)" style="cursor: default;"><img src="{$sdgScriptPath}/skins/down-arrow.png"></a> END; } $text .= <<<END \t\t\t\t\t{$filter_label}: \t\t\t\t\t</div> \t\t\t\t\t<div class="drilldown-filter-values" id="{$results_div_id}">{$results_line} \t\t\t\t\t</div> END; $f->dropTempTable(); return $text; }
/** * @deprecated as of SD 2.0 - will be removed when the "Filter:" * namespace goes away. */ static function load($filter_name) { $f = new SDFilter(); $f->setName($filter_name); $properties_used = SDUtils::getValuesForProperty($filter_name, SD_NS_FILTER, '_SD_CP', SD_SP_COVERS_PROPERTY, SMW_NS_PROPERTY); if (count($properties_used) > 0) { $f->setProperty($properties_used[0]); // This may not be necessary, or useful. $f->property_type = 'page'; } $proptitle = Title::newFromText($f->property, SMW_NS_PROPERTY); if ($proptitle != null) { $f->loadPropertyTypeFromProperty(); } $categories = SDUtils::getValuesForProperty($filter_name, SD_NS_FILTER, '_SD_VC', SD_SP_GETS_VALUES_FROM_CATEGORY, NS_CATEGORY); if (count($categories) > 0) { $f->setCategory($categories[0]); } elseif ($f->property_type === 'boolean') { $f->allowed_values = array('0', '1'); } else { $f->allowed_values = array(); } // Set list of possible applied filters if allowed values // array was set. foreach ($f->allowed_values as $allowed_value) { $f->possible_applied_filters[] = SDAppliedFilter::create($f, $allowed_value); } return $f; }
/** * Print the line showing 'AND' values for a filter that has not * been applied to the drilldown */ function printUnappliedFilterLine($f, $cur_url = null) { global $sdgScriptPath; global $sdgMinValuesForComboBox; global $sdgFiltersSmallestFontSize, $sdgFiltersLargestFontSize; $f->createTempTable(); $found_results_for_filter = false; if (count($f->allowed_values) == 0) { if ($f->property_type == 'date') { $filter_values = $f->getTimePeriodValues(); } else { $filter_values = $f->getAllValues(); } if (!is_array($filter_values)) { $f->dropTempTable(); return $this->printFilterLine($f->name, false, false, $filter_values); } if (count($filter_values) > 0) { $found_results_for_filter = true; } } else { $filter_values = array(); foreach ($f->allowed_values as $value) { $new_filter = SDAppliedFilter::create($f, $value); $num_results = $this->getNumResults($this->subcategory, $this->all_subcategories, $new_filter); if ($num_results > 0) { $filter_values[$value] = $num_results; } } } // Now get values for 'Other' and 'None', as well // - don't show 'Other' if filter values were // obtained dynamically. if (count($f->allowed_values) > 0) { $other_filter = SDAppliedFilter::create($f, ' other'); $num_results = $this->getNumResults($this->subcategory, $this->all_subcategories, $other_filter); if ($num_results > 0) { $filter_values['_other'] = $num_results; } } // show 'None' only if any other results have been found, and // if it's not a numeric filter if (count($f->allowed_values) > 0) { $fv = SDFilterValue::create($f->allowed_values[0]); if (!$fv->is_numeric) { $none_filter = SDAppliedFilter::create($f, ' none'); $num_results = $this->getNumResults($this->subcategory, $this->all_subcategories, $none_filter); if ($num_results > 0) { $filter_values['_none'] = $num_results; } } } $filter_name = urlencode(str_replace(' ', '_', $f->name)); $normal_filter = true; if (count($filter_values) == 0) { $results_line = '(' . wfMessage('sd_browsedata_novalues')->text() . ')'; } elseif ($f->property_type == 'number') { $results_line = $this->printNumberRanges($filter_name, $filter_values); } elseif (count($filter_values) >= $sdgMinValuesForComboBox) { $results_line = $this->printComboBoxInput($filter_name, 0, $filter_values); $normal_filter = false; } else { // If $cur_url wasn't passed in, we have to create it. $cur_url = $this->makeBrowseURL($this->category, $this->applied_filters, $this->subcategory, $f->name); $cur_url .= strpos($cur_url, '?') ? '&' : '?'; $results_line = $this->printUnappliedFilterValues($cur_url, $f, $filter_values); } $text = $this->printFilterLine($f->name, false, $normal_filter, $results_line); $f->dropTempTable(); return $text; }