Guest User

Untitled

a guest
Oct 22nd, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.67 KB | None | 0 0
  1.     private function setwhere($a)
  2.     {
  3.         $change=array(
  4.         'lessThan'=>' < :p',
  5.         'greaterThan'=>' > :p',
  6.         'lessThanOrEqual'=>' <= :p',
  7.         'greaterThanOrEqual'=>' >= :p',
  8.         'betweenInclusive'=>' between :1p and :2p',
  9.         'notEqual'=>' != :p',
  10.         'startsWith'=>' like :p',
  11.         'endsWith'=>' like :p',
  12.         'notStartsWith'=>' not like :p',
  13.         'notEndsWith'=>' not like :p',
  14.         'iContains'=>' like :p',
  15.         'notContains'=>' not like :p',
  16.         'inSet'=>' in :p',
  17.         'notInSet'=>' not in :p',
  18.         'isNull'=>' IS NULL',
  19.         'isNotNull'=>' IS NOT NULL ',
  20.         'exact match'=>' = :p',
  21.         'equals'=>' = :p '
  22.         );
  23.  
  24.  
  25.         $reval=array();
  26.         $ret='';
  27.         $tmp1=0;
  28.         foreach ($a as &$s)
  29.         {
  30.             $fieldName = \ApplicationHelpers::TranslateSCVarsToDoctrine($s['fieldName'], $this->getEntityClassname(), NULL);
  31.             $fieldName = str_ireplace('.', '_', $fieldName);
  32.             $tmp1++;
  33.             if(!isset($s['value']))
  34.             $s['value'] = '';
  35.  
  36.             switch ($s['operator']){
  37.                 case 'startsWith':
  38.                 case 'notStartsWith': $tmp=$s['value'].'%'; break;
  39.                 case 'endsWith':
  40.                 case 'notEndsWith': $tmp='%'.$s['value']; break;
  41.                 case 'iContains':
  42.                 case 'notContains': $tmp='%'.$s['value'].'%'; break;
  43.                 default: $tmp=$s['value'];break;
  44.             }
  45.             if($s['operator']=='betweenInclusive')
  46.             {
  47.                 $reval['1'.$fieldName.$tmp1]=$s['value'][0];
  48.                 $reval['2'.$fieldName.$tmp1]=$s['value'][1];
  49.             }
  50.             else
  51.             {
  52.                 $reval[$fieldName.$tmp1]=$tmp;
  53.             }
  54.             if($tmp1!=1)
  55.             {
  56.                 $ret=$ret.' and tmp.'. $fieldName.str_replace('p',$fieldName.$tmp1,$change[$s['operator']]);
  57.             }
  58.             else
  59.             {
  60.                    
  61.                 $ret='tmp.'.$fieldName.str_replace('p',$fieldName.$tmp1,$change[$s['operator']]);
  62.             }
  63.         }
  64.         return array($ret,$reval);
  65.     }
Add Comment
Please, Sign In to add comment