Beispiel #1
0
 /**
  * Test for getGISFunctions
  *
  * @return void
  */
 public function testGetGISFunctions()
 {
     $funcs = PMA_Util::getGISFunctions();
     $this->assertArrayHasKey('Dimension', $funcs);
     $this->assertArrayHasKey('GeometryType', $funcs);
     $this->assertArrayHasKey('MBRDisjoint', $funcs);
 }
Beispiel #2
0
 /**
  * Generates HTML for a geometrical function column to be displayed in table
  * search selection form
  *
  * @param integer $column_index index of current column in $columnTypes array
  *
  * @return string the generated HTML
  */
 private function _getGeomFuncHtml($column_index)
 {
     $html_output = '';
     // return if geometrical column is not present
     if (!$this->_geomColumnFlag) {
         return $html_output;
     }
     /**
      * Displays 'Function' column if it is present
      */
     $html_output .= '<td>';
     $geom_types = PMA_Util::getGISDatatypes();
     // if a geometry column is present
     if (in_array($this->_columnTypes[$column_index], $geom_types)) {
         $html_output .= '<select class="geom_func" name="geom_func[' . $column_index . ']">';
         // get the relevant list of GIS functions
         $funcs = PMA_Util::getGISFunctions($this->_columnTypes[$column_index], true, true);
         /**
          * For each function in the list of functions,
          * add an option to select list
          */
         foreach ($funcs as $func_name => $func) {
             $name = isset($func['display']) ? $func['display'] : $func_name;
             $html_output .= '<option value="' . htmlspecialchars($name) . '">' . htmlspecialchars($name) . '</option>';
         }
         $html_output .= '</select>';
     } else {
         $html_output .= '&nbsp;';
     }
     $html_output .= '</td>';
     return $html_output;
 }
 /**
  * Return the where clause for a geometrical column.
  *
  * @param mixed  $criteriaValues Search criteria input
  * @param string $names          Name of the column on which search is submitted
  * @param string $func_type      Search function/operator
  * @param string $types          Type of the field
  * @param bool   $geom_func      Whether geometry functions should be applied
  *
  * @return string part of where clause.
  */
 private function _getGeomWhereClause($criteriaValues, $names, $func_type, $types, $geom_func = null)
 {
     $geom_unary_functions = array('IsEmpty' => 1, 'IsSimple' => 1, 'IsRing' => 1, 'IsClosed' => 1);
     $where = '';
     // Get details about the geometry functions
     $geom_funcs = PMA_Util::getGISFunctions($types, true, false);
     // New output type is the output type of the function being applied
     $types = $geom_funcs[$geom_func]['type'];
     // If the function takes a single parameter
     if ($geom_funcs[$geom_func]['params'] == 1) {
         $backquoted_name = $geom_func . '(' . PMA_Util::backquote($names) . ')';
     } else {
         // If the function takes two parameters
         // create gis data from the criteria input
         $gis_data = PMA_Util::createGISData($criteriaValues);
         $where = $geom_func . '(' . PMA_Util::backquote($names) . ',' . $gis_data . ')';
         return $where;
     }
     // If the where clause is something like 'IsEmpty(`spatial_col_name`)'
     if (isset($geom_unary_functions[$geom_func]) && trim($criteriaValues) == '') {
         $where = $backquoted_name;
     } elseif (in_array($types, PMA_Util::getGISDatatypes()) && !empty($criteriaValues)) {
         // create gis data from the criteria input
         $gis_data = PMA_Util::createGISData($criteriaValues);
         $where = $backquoted_name . ' ' . $func_type . ' ' . $gis_data;
     }
     return $where;
 }