/** * Returns the HTML for setting the filter options, for the * Semantic Drilldown section in Page Schemas' "edit schema" page */ public static function getFieldEditingHTML($psField) { //$require_filter_label = wfMessage( 'sd_createfilter_requirefilter' )->text(); $filter_array = array(); $hasExistingValues = false; if (!is_null($psField)) { $filter_array = $psField->getObject('semanticdrilldown_Filter'); if (!is_null($filter_array)) { $hasExistingValues = true; } } $filterName = PageSchemas::getValueFromObject($filter_array, 'name'); $selectedCategory = PageSchemas::getValueFromObject($filter_array, 'ValuesFromCategory'); $fromCategoryAttrs = array(); if (!is_null($selectedCategory)) { $fromCategoryAttrs['checked'] = true; } // Have the first radiobutton ("Use all values of this // property for the filter") checked if none of the other // options have been selected - unlike the others, there's // no XML to define this option. $usePropertyValuesAttr = array(); if (empty($selectedCategory)) { $usePropertyValuesAttr['checked'] = true; } $html_text = '<div class="editSchemaMinorFields">' . "\n"; $html_text .= '<p>' . wfMessage('ps-optional-name')->text() . ' '; $html_text .= Html::input('sd_filter_name_num', $filterName, 'text', array('size' => 25)) . "</p>\n"; $html_text .= wfMessage('sd-pageschemas-values')->text() . ":\n"; $html_text .= Html::input('sd_values_source_num', 'property', 'radio', $usePropertyValuesAttr) . ' '; $html_text .= wfMessage('sd_createfilter_usepropertyvalues')->text() . "\n"; $html_text .= Html::input('sd_values_source_num', 'category', 'radio', $fromCategoryAttrs) . "\n"; $html_text .= "\t" . wfMessage('sd_createfilter_usecategoryvalues')->text() . "\n"; $categories = SDUtils::getTopLevelCategories(); $categoriesHTML = ""; foreach ($categories as $category) { $categoryOptionAttrs = array(); $category = str_replace('_', ' ', $category); if ($category == $selectedCategory) { $categoryOptionAttrs['selected'] = true; } $categoriesHTML .= "\t" . Html::element('option', $categoryOptionAttrs, $category) . "\n"; } $html_text .= "\t" . Html::rawElement('select', array('id' => 'category_dropdown', 'name' => 'sd_category_name_num'), "\n" . $categoriesHTML) . "\n"; $html_text .= "\t</p>\n"; $html_text .= "\t</div>\n"; return array($html_text, $hasExistingValues); }
/** * Returns the HTML for setting the filter options, for the * Semantic Drilldown section in Page Schemas' "edit schema" page */ public static function getFieldEditingHTML( $psField ){ //$require_filter_label = wfMsg( 'sd_createfilter_requirefilter' ); $filter_array = array(); $hasExistingValues = false; if ( !is_null( $psField ) ) { $filter_array = $psField->getObject( 'semanticdrilldown_Filter' ); if ( !is_null( $filter_array ) ) { $hasExistingValues = true; } } $filterName = PageSchemas::getValueFromObject( $filter_array, 'name' ); $selectedCategory = PageSchemas::getValueFromObject( $filter_array, 'ValuesFromCategory' ); $fromCategoryAttrs = array(); if ( !is_null( $selectedCategory ) ) { $fromCategoryAttrs['checked'] = true; } $dateRangesAttrs = array(); $year_value = wfMsgForContent( 'sd_filter_year' ); $yearOptionAttrs = array( 'value' => $year_value ); $month_value = wfMsgForContent( 'sd_filter_month' ); $monthOptionAttrs = array( 'value' => $month_value ); $filterTimePeriod = PageSchemas::getValueFromObject( $filter_array, 'TimePeriod' ); if ( !is_null( $filterTimePeriod ) ) { $dateRangesAttrs['checked'] = true; if ( $filterTimePeriod == $year_value ) { $yearOptionAttrs['selected'] = true; } else { $monthOptionAttrs['selected'] = true; } } $manualSourceAttrs = array(); $filterValuesAttrs = array( 'size' => 40 ); $values_array = PageSchemas::getValueFromObject( $filter_array, 'Values' ); if ( !is_null( $values_array ) ) { $manualSourceAttrs['checked'] = true; $filterValuesStr = implode( ', ', $values_array ); } else { $filterValuesStr = ''; } // Have the first radiobutton ("Use all values of this // property for the filter") checked if none of the other // options have been selected - unlike the others, there's // no XML to define this option. $usePropertyValuesAttr = array(); if ( empty( $selectedCategory ) && empty( $filterTimePeriod ) && empty( $filterValuesStr ) ) { $usePropertyValuesAttr['checked'] = true; } // The "input type" field. $combo_box_value = wfMsgForContent( 'sd_filter_combobox' ); $date_range_value = wfMsgForContent( 'sd_filter_daterange' ); $valuesListAttrs = array( 'value' => '' ); $comboBoxAttrs = array( 'value' => $combo_box_value ); $dateRangeAttrs = array( 'value' => $date_range_value ); $input_type_val = PageSchemas::getValueFromObject( $filter_array, 'InputType' ); if ( $input_type_val == $combo_box_value ) { $comboBoxAttrs['selected'] = true; } elseif ( $input_type_val == $date_range_value ) { $dateRangeAttrs['selected'] = true; } else { $valuesListAttrs['selected'] = true; } $html_text = '<p>' . wfMsg( 'ps-optional-name' ) . ' '; $html_text .= Html::input( 'sd_filter_name_num', $filterName, 'text', array( 'size' => 25 ) ) . "</p>\n"; $html_text .= '<fieldset><legend>' . wfMsg( 'sd-pageschemas-values' ) . '</legend>' . "\n"; $html_text .= '<p>' . Html::input( 'sd_values_source_num', 'property', 'radio', $usePropertyValuesAttr ) . ' '; $html_text .= wfMsg( 'sd_createfilter_usepropertyvalues' ) . "</p>\n"; $html_text .= "\t<p>\n"; $html_text .= Html::input( 'sd_values_source_num', 'category', 'radio', $fromCategoryAttrs ) . "\n"; $html_text .= "\t" . wfMsg( 'sd_createfilter_usecategoryvalues' ) . "\n"; $categories = SDUtils::getTopLevelCategories(); $categoriesHTML = ""; foreach ( $categories as $category ) { $categoryOptionAttrs = array(); $category = str_replace( '_', ' ', $category ); if ( $category == $selectedCategory) { $categoryOptionAttrs['selected'] = true; } $categoriesHTML .= "\t" . Html::element( 'option', $categoryOptionAttrs, $category ) . "\n"; } $html_text .= "\t" . Html::rawElement( 'select', array( 'id' => 'category_dropdown', 'name' => 'sd_category_name_num' ), "\n" . $categoriesHTML ) . "\n"; $html_text .= "\t</p>\n"; $html_text .= "\t<p>\n"; $html_text .= "\t" . Html::input( 'sd_values_source_num', 'dates', 'radio', $dateRangesAttrs ) . "\n"; $html_text .= "\t" . wfMsg( 'sd_createfilter_usedatevalues' ) . "\n"; $dateRangeDropdown = Html::element( 'option', $yearOptionAttrs, wfMsg( 'sd_filter_year' ) ) . "\n"; $dateRangeDropdown .= Html::element( 'option', $monthOptionAttrs, wfMsg( 'sd_filter_month' ) ) . "\n"; $html_text .= Html::rawElement( 'select', array( 'name' => 'sd_time_period_num', 'id' => 'time_period_dropdown' ), "\n" . $dateRangeDropdown ) . "\n"; $html_text .= "</p>\n<p>\n"; $html_text .= "\t" . Html::input( 'sd_values_source_num', 'manual', 'radio', $manualSourceAttrs ) . "\n"; $html_text .= "\t" . wfMsg( 'sd_createfilter_entervalues' ) . "\n"; $html_text .= "\t" . Html::input( 'sd_filter_values_num', $filterValuesStr, 'text', $filterValuesAttrs ) . "\n"; $html_text .= "\t</p>\n"; $html_text .= "</fieldset>\n"; $html_text .= '<p>' . wfMsg( 'sd_createfilter_inputtype' ) . "\n"; $inputTypeOptionsHTML = "\t" . Html::element( 'option', $valuesListAttrs, wfMsg( 'sd_createfilter_listofvalues' ) ) . "\n"; $inputTypeOptionsHTML .= "\t" . Html::element( 'option', $comboBoxAttrs, wfMsg( 'sd_filter_combobox' ) ) . "\n"; $inputTypeOptionsHTML .= "\t" . Html::element( 'option', $dateRangeAttrs, wfMsg( 'sd_filter_daterange' ) ) . "\n"; $html_text .= Html::rawElement( 'select', array( 'name' => 'sd_input_type_num', 'id' => 'input_type_dropdown' ), $inputTypeOptionsHTML ) . "\n"; $html_text .= "</p>\n"; return array( $html_text, $hasExistingValues ); }