public function dbExternalToSchemaValue($v, EarthIT_Schema_Field $f, EarthIT_Schema_ResourceClass $rc) { if ($v === null) { return null; } else { if (self::valuesOfTypeShouldBeSelectedAsGeoJson($f->getType()) or self::valuesOfTypeShouldBeSelectedAsJson($f->getType())) { return EarthIT_JSON::decode($v); } else { return $v; } } }
public static function fieldValueFilter($scheme, $pattern, EarthIT_Schema_Field $field, EarthIT_Schema_ResourceClass $rc) { switch ($scheme) { case 'not': // Oh look this is kind of a silly way to do it: $toBeNegated = self::parsePattern($field->getName(), $pattern, $rc); return new EarthIT_Storage_Filter_NegatedItemFilter($toBeNegated); case 'is': if ($pattern === 'null') { $comparisonOp = EarthIT_Storage_Filter_ComparisonOps::exactMatch2(); $vExp = EarthIT_Storage_Filter_NullValueExpression::getInstance(); } else { throw new Exception("'is:' operator only supports 'null' pattern; given: " . var_export($pattern, true)); } break; case 'eq': $value = EarthIT_Storage_Util::cast($pattern, $field->getType()->getPhpTypeName()); return new EarthIT_Storage_Filter_ExactMatchFieldValueFilter($field, $rc, $value); case 'in': $values = array(); if ($pattern === '') { $pattern = array(); } $patternValues = is_array($pattern) ? $pattern : explode(',', $pattern); foreach ($patternValues as $p) { $values[] = EarthIT_Storage_Util::cast($p, $field->getType()->getPhpTypeName()); } if (count($values) == 0) { return new EarthIT_Storage_Filter_OredItemFilter(array()); } $comparisonOp = EarthIT_Storage_Filter_InListComparisonOp::getInstance(); $vExp = new EarthIT_Storage_Filter_ListValueExpression($values); break; case 'lt': case 'le': case 'ge': case 'gt': $comparisonOp = EarthIT_Storage_Filter_ComparisonOps::get($scheme); $value = EarthIT_Storage_Util::cast($pattern, $field->getType()->getPhpTypeName()); $vExp = new EarthIT_Storage_Filter_ScalarValueExpression($value); break; case 'like': return new EarthIT_Storage_Filter_PatternFieldValueFilter($field, $rc, $pattern, true); default: throw new Exception("Unrecognized pattern scheme: '{$scheme}'"); } return new EarthIT_Storage_Filter_FieldValueComparisonFilter($field, $rc, $comparisonOp, $vExp); }
public function dbExternalToSchemaValue($v, EarthIT_Schema_Field $f, EarthIT_Schema_ResourceClass $rc) { if ($v === null) { return null; } else { if (self::valuesOfTypeShouldBeSelectedAsGeoJson($f->getType()) or self::valuesOfTypeShouldBeSelectedAsJson($f->getType())) { return EarthIT_JSON::decode($v); } else { if (($dataType = $f->getType()) && ($phpType = $dataType->getPhpTypeName()) !== null) { return EarthIT_Storage_Util::cast($v, $phpType); } else { return $v; } } } }