Ejemplo n.º 1
0
 static function create($filter, $values, $search_terms = null, $lower_date = null, $upper_date = null)
 {
     $af = new SDAppliedFilter();
     $af->filter = $filter;
     if ($search_terms != null) {
         $af->search_terms = array();
         foreach ($search_terms as $search_term) {
             $af->search_terms[] = htmlspecialchars(str_replace('_', ' ', $search_term));
         }
     }
     if ($lower_date != null) {
         $af->lower_date = $lower_date;
         $af->lower_date_string = SDUtils::monthToString($lower_date['month']) . " " . $lower_date['day'] . ", " . $lower_date['year'];
     }
     if ($upper_date != null) {
         $af->upper_date = $upper_date;
         $af->upper_date_string = SDUtils::monthToString($upper_date['month']) . " " . $upper_date['day'] . ", " . $upper_date['year'];
     }
     if (!is_array($values)) {
         $values = array($values);
     }
     foreach ($values as $val) {
         $filter_val = SDFilterValue::create($val, $filter);
         $af->values[] = $filter_val;
     }
     return $af;
 }
Ejemplo n.º 2
0
    /**
     * 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;
    }
Ejemplo n.º 3
0
 /**
  * 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;
 }