/**
  * @param mixed        $value
  * @param ColumnSchema $info
  * @param array        $params
  *
  * @return int|null|string
  * @throws BadRequestException
  */
 protected function parseFilterValue($value, ColumnSchema $info, array &$params)
 {
     if (0 !== strpos($value, ':')) {
         // remove quoting on strings if used, i.e. 1.x required them
         if (is_string($value) && (0 === strcmp("'" . trim($value, "'") . "'", $value) || 0 === strcmp('"' . trim($value, '"') . '"', $value))) {
             $value = trim($value, '"\'');
         }
         // if not already a replacement parameter, evaluate it
         //            $value = $this->dbConn->getSchema()->parseValueForSet($value, $info);
         switch ($cnvType = DbUtilities::determinePhpConversionType($info->type)) {
             case 'int':
                 if (!is_int($value)) {
                     if (!ctype_digit($value)) {
                         throw new BadRequestException("Field '{$info->getName(true)}' must be a valid integer.");
                     } else {
                         $value = intval($value);
                     }
                 }
                 break;
             case 'time':
                 $cfgFormat = \Config::get('df.db_time_format');
                 $outFormat = 'H:i:s.u';
                 $value = DbUtilities::formatDateTime($outFormat, $value, $cfgFormat);
                 break;
             case 'date':
                 $cfgFormat = \Config::get('df.db_date_format');
                 $outFormat = 'Y-m-d';
                 $value = DbUtilities::formatDateTime($outFormat, $value, $cfgFormat);
                 break;
             case 'datetime':
                 $cfgFormat = \Config::get('df.db_datetime_format');
                 $outFormat = 'Y-m-d H:i:s';
                 $value = DbUtilities::formatDateTime($outFormat, $value, $cfgFormat);
                 break;
             case 'timestamp':
                 $cfgFormat = \Config::get('df.db_timestamp_format');
                 $outFormat = 'Y-m-d H:i:s';
                 $value = DbUtilities::formatDateTime($outFormat, $value, $cfgFormat);
                 break;
             default:
                 break;
         }
         $paramName = ':cf_' . count($params);
         // positionally unique
         $params[$paramName] = $value;
         $value = $paramName;
     }
     return $value;
 }
Exemple #2
0
 /**
  * @param ColumnSchema $field_info
  *
  * @return array
  */
 public function parseFieldForBinding(ColumnSchema $field_info)
 {
     $pdoType = $field_info->allowNull ? null : $field_info->pdoType;
     $phpType = is_null($pdoType) ? $field_info->phpType : null;
     return ['name' => $field_info->getName(true), 'pdo_type' => $pdoType, 'php_type' => $phpType];
 }