fmsystem-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Fmsystem-commits] [16785]


From: nelson . guerra
Subject: [Fmsystem-commits] [16785]
Date: Thu, 25 May 2017 23:33:56 -0400 (EDT)

Revision: 16785
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=16785
Author:   nelson224
Date:     2017-05-25 23:33:56 -0400 (Thu, 25 May 2017)
Log Message:
-----------


Modified Paths:
--------------
    branches/dev-syncromind-2/property/inc/class.soreport.inc.php

Modified: branches/dev-syncromind-2/property/inc/class.soreport.inc.php
===================================================================
--- branches/dev-syncromind-2/property/inc/class.soreport.inc.php       
2017-05-25 21:35:51 UTC (rev 16784)
+++ branches/dev-syncromind-2/property/inc/class.soreport.inc.php       
2017-05-26 03:33:56 UTC (rev 16785)
@@ -257,28 +257,115 @@
                        return $values;
                }
                
-               private function _build_conditions($criteria)
+               private function _is_date( $str ) {
+                       try {
+                               $dt = new DateTime( trim($str) );
+                       }
+                       catch( Exception $e ) {
+                               return false;
+                       }
+                       $month = $dt->format('m');
+                       $day = $dt->format('d');
+                       $year = $dt->format('Y');
+                       if( checkdate($month, $day, $year) ) {
+                               return true;
+                       }
+                       else {
+                               return false;
+                       }
+               }
+
+               private function _build_conditions_equal($param, $type)
+               {               
+                       $result = '';
+                       
+                       switch ($type) 
+                       {
+                               case 'character varying':
+                               case 'text':
+                                       $result = $param['field']." 
".$this->operators[$param['operator']]." '".$param['value1']."'";
+                                       if ($param['conector'] && 
$param['value2'] != '')
+                                       {
+                                               $result .= " 
".$param['conector']." ".$param['field']." 
".$this->operators[$param['operator']]." '".$param['value2']."'";
+                                       }
+                                       break;
+                               case 'integer':
+                               case 'smallint':
+                               case 'numeric':
+                                       if (is_numeric($param['value1']))
+                                       {
+                                               $result = $param['field']." 
".$this->operators[$param['operator']]." ".$param['value1'];
+                                               if ($param['conector'] && 
is_numeric(['value2']))
+                                               {
+                                                       $result .= " 
".$param['conector']." ".$param['field']." 
".$this->operators[$param['operator']]." ".$param['value2'];
+                                               }
+                                       }
+                                       break;
+                               case 'date':
+                               case 'timestamp without time zone':
+                                       if ($this->_is_date($param['value1']))
+                                       {
+                                               $result = $param['field']." 
".$this->operators[$param['operator']]." '".$param['value1']."'";
+                                               if ($param['conector'] && 
$this->_is_date($param['value2']))
+                                               {
+                                                       $result .= " 
".$param['conector']." ".$param['field']." 
".$this->operators[$param['operator']]." '".$param['value1']."'";
+                                               }
+                                       }
+                       }                               
+               
+                       return $result;
+               }
+               
+               private function _build_conditions($criteria, $id)
                {
+                       $columns = $this->get_view_columns($id);
+                       $_columns = array();
+                       foreach ($columns as $column)
+                       {
+                               $_columns[$column['name']] = $column['type'];
+                       }
+                       
                        $where = array();
                        foreach ($criteria as $param)
                        {
-                               switch (true) {
+                               switch (true) 
+                               {
                                        case 
(array_key_exists($param['operator'], $this->operators_equal)):
-                                               $where[] =  $param['field']." 
".$this->operators[$param['operator']]." ".$param['value1'];
+                                               $result =  
$this->_build_conditions_equal($param, $_columns[$param['field']]);
                                                break;
                                        case 
(array_key_exists($param['operator'], $this->operators_between)):
-                                               $where[] =  $param['field']." 
".$this->operators[$param['operator']]." ".$param['value1']." AND 
".$param['value2'];
+                                               if ($param['value1'] != '' && 
$param['value2'] != '')
+                                               {
+                                                       $result =  
$param['field']."::text ".$this->operators[$param['operator']]." 
'".$param['value1']."' AND '".$param['value2']."'";
+                                               }
                                                break;
                                        case 
(array_key_exists($param['operator'], $this->operators_like)):
-                                               $where[] =  $param['field']." 
".$this->operators[$param['operator']]." '%".$param['value1']."%'";
+                                               if ($param['value1'] != '')
+                                               {
+                                                       $result =  
$param['field']."::text ".$this->operators[$param['operator']]." 
'%".$param['value1']."%'";
+                                                       if ($param['conector'] 
&& $param['value2'] != '')
+                                                       {
+                                                               $result .= " 
".$param['conector']." ".$param['field']."::text 
".$this->operators[$param['operator']]." '%".$param['value2']."%'";
+                                                       }                       
                                
+                                               }
                                                break;
                                        case 
(array_key_exists($param['operator'], $this->operators_null)):
-                                               $where[] =  $param['field']." 
".$this->operators[$param['operator']];
+                                               $result =  $param['field']." 
".$this->operators[$param['operator']];
                                                break;
                                        case 
(array_key_exists($param['operator'], $this->operators_in)):
-                                               $where[] =  $param['field']." 
".$this->operators[$param['operator']]." (".$param['value1'].")";
+                                               if ($param['value1'] != '')
+                                               {
+                                                       $values = 
array_map('trim', explode(',', $param['value1']));
+                                                       $_string = 
"'".implode("','", $values)."'";
+                                                       $result =  
$param['field']."::text ".$this->operators[$param['operator']]." 
(".$_string.")";
+                                               }
                                                break;
-                               }                               
+                               }               
+                               
+                               if ($result)
+                               {
+                                       $where[] = $result;
+                               }
                        }
                        
                        return $where;
@@ -303,7 +390,7 @@
                        
                        $group = implode(',', $jsonB['group']);
                        $order = 'ORDER BY '.$group.' ASC';
-                       $cond = $this->_build_conditions($jsonB['criteria']);
+                       $cond = $this->_build_conditions($jsonB['criteria'], 
$id);
                        
                        if ($cond)
                        {




reply via email to

[Prev in Thread] Current Thread [Next in Thread]