jenkins-bot has submitted this change and it was merged.

Change subject: Removed duplicate retrieval of filters in drilldown
......................................................................


Removed duplicate retrieval of filters in drilldown

Change-Id: Id6d9cc640aacd8ce83241046b85c1a5bbbb4a628
---
M drilldown/CargoSpecialDrilldown.php
1 file changed, 14 insertions(+), 24 deletions(-)

Approvals:
  Yaron Koren: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/drilldown/CargoSpecialDrilldown.php 
b/drilldown/CargoSpecialDrilldown.php
index 42930a6..c766e50 100644
--- a/drilldown/CargoSpecialDrilldown.php
+++ b/drilldown/CargoSpecialDrilldown.php
@@ -62,15 +62,15 @@
                }
 
                $tableSchemas = CargoUtils::getTableSchemas( array( $tableName 
) );
-               $filters = array();
+               $all_filters = array();
                foreach ( $tableSchemas[$tableName]->mFieldDescriptions as 
$fieldName => $fieldDescription ) {
                        // Skip "hidden" fields.
                        if ( $fieldDescription->mIsHidden ) {
                                continue;
                        }
 
-                       // Skip coordinate fields.
-                       if ( $fieldDescription->mType == 'Coordinates' ) {
+                       // Some field types shouldn't get a filter at all.
+                       if ( in_array( $fieldDescription->mType, array( 'Text', 
'File', 'Coordinates', 'URL', 'Email', 'Wikitext', 'Searchtext' ) ) ) {
                                continue;
                        }
 
@@ -78,16 +78,16 @@
                        $curFilter->setName( $fieldName );
                        $curFilter->setTableName( $tableName );
                        $curFilter->setFieldDescription( $fieldDescription );
-                       $filters[] = $curFilter;
+                       $all_filters[] = $curFilter;
                }
 
                $filter_used = array();
-               foreach ( $filters as $i => $filter ) {
+               foreach ( $all_filters as $i => $filter ) {
                        $filter_used[] = false;
                }
                $applied_filters = array();
                $remaining_filters = array();
-               foreach ( $filters as $i => $filter ) {
+               foreach ( $all_filters as $i => $filter ) {
                        $filter_name = str_replace( array( ' ', "'" ), array( 
'_', "\'" ), $filter->name );
                        $search_terms = $request->getArray( '_search_' . 
$filter_name );
                        $lower_date = $request->getArray( '_lower_' . 
$filter_name );
@@ -107,9 +107,9 @@
                                $filter_used[$i] = true;
                        }
                }
-               // add every unused filter to the $remaining_filters array,
-               // unless it requires some other filter that hasn't been applied
-               foreach ( $filters as $i => $filter ) {
+               // Add every unused filter to the $remaining_filters array,
+               // unless it requires some other filter that hasn't been 
applied.
+               foreach ( $all_filters as $i => $filter ) {
                        $matched_all_required_filters = true;
                        foreach ( $filter->required_filters as $required_filter 
) {
                                $found_match = false;
@@ -130,7 +130,7 @@
 
                $out->addHTML( "\n\t\t\t\t<div class=\"drilldown-results\">\n" 
);
                $rep = new CargoDrilldownPage(
-                       $tableName, $applied_filters, $remaining_filters, 
$offset, $limit );
+                       $tableName, $all_filters, $applied_filters, 
$remaining_filters, $offset, $limit );
                $num = $rep->execute( $query );
                $out->addHTML( "\n\t\t\t</div> <!-- drilldown-results -->\n" );
 
@@ -148,6 +148,7 @@
 
 class CargoDrilldownPage extends QueryPage {
        public $tableName = "";
+       public $all_filters = array();
        public $applied_filters = array();
        public $remaining_filters = array();
        public $showSingleTable = false;
@@ -161,10 +162,11 @@
         * @param int $offset
         * @param int $limit
         */
-       function __construct( $tableName, $applied_filters, $remaining_filters, 
$offset, $limit ) {
+       function __construct( $tableName, $all_filters, $applied_filters, 
$remaining_filters, $offset, $limit ) {
                parent::__construct( 'Drilldown' );
 
                $this->tableName = $tableName;
+               $this->all_filters = $all_filters;
                $this->applied_filters = $applied_filters;
                $this->remaining_filters = $remaining_filters;
                $this->offset = $offset;
@@ -977,20 +979,8 @@
                $filtersHTML = "                                <div 
class=\"drilldown-filters\">\n";
                $cur_url = $this->makeBrowseURL( $this->tableName, 
$this->applied_filters );
                $cur_url .= ( strpos( $cur_url, '?' ) ) ? '&' : '?';
-               $tableSchemas = CargoUtils::getTableSchemas( array( 
$this->tableName ) );
-               $tableSchema = $tableSchemas[$this->tableName];
 
-               $numFilters = 0;
-               foreach ( $tableSchema->mFieldDescriptions as $fieldName => 
$fieldDescription ) {
-                       $fieldType = $fieldDescription->mType;
-                       // Some field types shouldn't get a filter at all.
-                       if ( in_array( $fieldType, array( 'Text', 'File', 
'URL', 'Email', 'Wikitext', 'Searchtext' ) ) ) {
-                               continue;
-                       }
-                       $f = new CargoFilter();
-                       $f->setName( $fieldName );
-                       $f->setTableName( $this->tableName );
-                       $f->setFieldDescription( $fieldDescription );
+               foreach ( $this->all_filters as $f ) {
                        foreach ( $this->applied_filters as $af ) {
                                if ( $af->filter->name == $f->name ) {
                                        if ( $fieldType == 'Date' || $fieldType 
== 'Integer' || $fieldType == 'Float' ) {

-- 
To view, visit https://gerrit.wikimedia.org/r/315720
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Id6d9cc640aacd8ce83241046b85c1a5bbbb4a628
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/Cargo
Gerrit-Branch: master
Gerrit-Owner: Yaron Koren <yaro...@gmail.com>
Gerrit-Reviewer: Yaron Koren <yaro...@gmail.com>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to