protected function doFilterPageDatatableSearch($callBackParameters, $table, $searchTree)
    {
        // filter a data table array
        if ($table instanceof DataTable\Map) {
            foreach ($table->getDataTables() as $subTable) {
                $filteredSubTable = $this->doFilterPageDatatableSearch($callBackParameters, $subTable, $searchTree);

                if ($filteredSubTable->getRowsCount() > 0) {
                    // match found in a sub table, return and stop searching the others
                    return $filteredSubTable;
                }
            }

            // nothing found in all sub tables
            return new DataTable;
        }

        // filter regular data table
        if ($table instanceof DataTable) {
            // search for the first part of the tree search
            $search = array_shift($searchTree);
            $row = $table->getRowFromLabel($search);
            if ($row === false) {
                // not found
                $result = new DataTable;
                $result->setAllTableMetadata($table->getAllTableMetadata());
                return $result;
            }

            // end of tree search reached
            if (count($searchTree) == 0) {
                $result = $table->getEmptyClone();
                $result->addRow($row);
                $result->setAllTableMetadata($table->getAllTableMetadata());
                return $result;
            }

            // match found on this level and more levels remaining: go deeper
            $idSubTable = $row->getIdSubDataTable();
            $callBackParameters[7] = $idSubTable;

            /**
             * @var \Piwik\Period $period
             */
            $period = $table->getMetadata('period');
            if (!empty($period)) {
                $callBackParameters[3] = $period->getDateStart() . ',' . $period->getDateEnd();
            }

            $table = call_user_func_array('\Piwik\Archive::createDataTableFromArchive', $callBackParameters);
            return $this->doFilterPageDatatableSearch($callBackParameters, $table, $searchTree);
        }

        throw new Exception("For this API function, DataTable " . get_class($table) . " is not supported");
    }
protected function doFilterPageDatatableSearch($callBackParameters, $table, $searchTree)
    {
        // filter a data table array
        if ($table instanceof DataTable\Map) {
            foreach ($table->getDataTables() as $subTable) {
                $filteredSubTable = $this->doFilterPageDatatableSearch($callBackParameters, $subTable, $searchTree);

                if ($filteredSubTable->getRowsCount() > 0) {
                    // match found in a sub table, return and stop searching the others
                    return $filteredSubTable;
                }
            }

            // nothing found in all sub tables
            return new DataTable;
        }

        // filter regular data table
        if ($table instanceof DataTable) {
            // search for the first part of the tree search
            $search = array_shift($searchTree);
            $row = $table->getRowFromLabel($search);
            if ($row === false) {
                // not found
                $result = new DataTable;
                $result->setAllTableMetadata($table->getAllTableMetadata());
                return $result;
            }

            // end of tree search reached
            if (count($searchTree) == 0) {
                $result = $table->getEmptyClone();
                $result->addRow($row);
                $result->setAllTableMetadata($table->getAllTableMetadata());
                return $result;
            }

            // match found on this level and more levels remaining: go deeper
            $idSubTable = $row->getIdSubDataTable();
            $callBackParameters[7] = $idSubTable;

            /**
             * @var \Piwik\Period $period
             */
            $period = $table->getMetadata('period');
            if (!empty($period)) {
                $callBackParameters[3] = $period->getDateStart() . ',' . $period->getDateEnd();
            }

            $table = call_user_func_array('\Piwik\Archive::createDataTableFromArchive', $callBackParameters);
            return $this->doFilterPageDatatableSearch($callBackParameters, $table, $searchTree);
        }

        throw new Exception("For this API function, DataTable " . get_class($table) . " is not supported");
    }
protected function doFilterPageDatatableSearch ( $ callBackParameters , $ table , $ searchTree ) { // filter a data table array if ( $ table instanceof DataTable \ Map ) { foreach ( $ table -> getDataTables ( ) as $ subTable ) { $ filteredSubTable = $ this -> doFilterPageDatatableSearch ( $ callBackParameters , $ subTable , $ searchTree ) ; if ( $ filteredSubTable -> getRowsCount ( ) > 0 ) { // match found in a sub table, return and stop searching the others return $ filteredSubTable ; } } // nothing found in all sub tables return new DataTable ; } // filter regular data table if ( $ table instanceof DataTable ) { // search for the first part of the tree search $ search = array_shift ( $ searchTree ) ; $ row = $ table -> getRowFromLabel ( $ search ) ; if ( $ row === false ) { // not found $ result = new DataTable ; $ result -> setAllTableMetadata ( $ table -> getAllTableMetadata ( ) ) ; return $ result ; } // end of tree search reached if ( count ( $ searchTree ) == 0 ) { $ result = $ table -> getEmptyClone ( ) ; $ result -> addRow ( $ row ) ; $ result -> setAllTableMetadata ( $ table -> getAllTableMetadata ( ) ) ; return $ result ; } // match found on this level and more levels remaining: go deeper $ idSubTable = $ row -> getIdSubDataTable ( ) ; $ callBackParameters [ 7 ] = $ idSubTable ; /**
             * @var \Piwik\Period $period
             */ $ period = $ table -> getMetadata ( 'period' ) ; if ( ! empty ( $ period ) ) { $ callBackParameters [ 3 ] = $ period -> getDateStart ( ) . ',' . $ period -> getDateEnd ( ) ; } $ table = call_user_func_array ( '\Piwik\Archive::createDataTableFromArchive' , $ callBackParameters ) ; return $ this -> doFilterPageDatatableSearch ( $ callBackParameters , $ table , $ searchTree ) ; } throw new Exception ( "For this API function, DataTable " . get_class ( $ table ) . " is not supported" ) ; }
This looks very similar to LabelFilter.php should it be refactored somehow? FIXME
This looks very similar to LabelFilter . php should it be refactored somehow? FIXME