/**
  * 	getFilter
  *
  * 	prepares a comparison operator based statement, reading the operator
  * 	value from the incoming request
  *
  * @param array $filters
  * 	a filter array to add values to
  * @param array $rparams
  * 	incoming request filters
  * @param string $alias
  * 	object alias to use when building the statement
  * @param string $pttype
  * 	object type
  * @param string $sign
  * 	an operator to use when building the statement
  * @param string $datatype
  * 	data type
  * @param string $defaultvalue
  * 	default value
  *
  * @return array
  * 	comparison statement
  */
 function getFilter($filters, $rparams, $alias, $pttype, $sign, $datatype = NULL, $defaultvalue = NULL)
 {
     $novalue = (!isset($rparams[$pttype]) || empty($rparams[$pttype])) && is_null($defaultvalue);
     if ($novalue) {
         return $filters;
     }
     if (isset($rparams[$pttype]) && !empty($rparams[$pttype])) {
         $value = $rparams[$pttype];
     } else {
         $value = $defaultvalue;
     }
     if (!isset($filters['fnames'])) {
         $filters['fnames'] = array();
         $filters['fvalues'] = array();
     }
     $lalias = $alias . $pttype;
     $falias = str_replace('.', '_', $lalias);
     if ($sign == 'BETWEEN') {
         $filters['fnames'][] = "{$lalias} BETWEEN :{$falias1} AND :{$falias2}";
         return $filters;
         $filters['fvalues'][":{$falias1}"] = EasyContactFormsUtils::convert($value->values[0], $datatype, TRUE);
         $filters['fvalues'][":{$falias2}"] = EasyContactFormsUtils::convert($value->values[1], $datatype, TRUE);
         return $filters;
     }
     if ($sign == 'IN' || $sign == 'NOT IN') {
         $filters['fnames'][] = "{$lalias} {$sign} (:{$falias})";
         $values = array();
         foreach ($value->values as $vvalue) {
             $values[] = EasyContactFormsUtils::convert($vvalue, $datatype, TRUE);
         }
         $filters['fvalues'][":{$falias}"] = $values;
         return $filters;
     }
     $value = EasyContactFormsUtils::convert($value->values[0], $datatype, TRUE);
     if ($sign == 'LIKE') {
         $filters['fnames'][] = "{$lalias} LIKE :{$falias}";
         $filters['fvalues'][":{$falias}"] = "%{$value}%";
         return $filters;
     }
     $filters['fnames'][] = "{$lalias} {$sign} :{$falias}";
     $filters['fvalues'][":{$falias}"] = $value;
     return $filters;
 }
Ejemplo n.º 2
0
 /**
  * 	parseRequest
  *
  * 	prepares an object before update
  *
  * @param object $request
  * 	request values
  * @param string $field
  * 	object field name
  * @param string $datatype
  * 	data type name
  */
 function parseRequest($request, $field, $datatype)
 {
     if (!isset($request->{$field})) {
         return $request;
     }
     $request->{$field} = EasyContactFormsUtils::convert($request->{$field}, $datatype);
     return $request;
 }