// Improve collections : where() method reworked (prototype changed) + validation of fields

This commit is contained in:
rMalie
2011-12-19 16:57:28 +00:00
parent 219f3ac870
commit b2b678ab3d
15 changed files with 240 additions and 67 deletions
+39 -32
View File
@@ -300,42 +300,49 @@ abstract class ObjectModelCore
}
// Format field value
switch ($data['type'])
{
case self::TYPE_INT :
$fields[$field] = (int)$value;
break;
case self::TYPE_BOOL :
$fields[$field] = (int)$value;
break;
case self::TYPE_FLOAT :
$fields[$field] = (float)$value;
break;
case self::TYPE_DATE :
$fields[$field] = pSQL($value);
break;
case self::TYPE_STRING :
$fields[$field] = pSQL($value);
break;
case self::TYPE_HTML :
$fields[$field] = pSQL($value, true);
break;
default :
if (method_exists($this, 'formatType'.$data['type']))
$fields[$field] = $this->{'formatType'.$data['type']}($value);
break;
}
$fields[$field] = ObjectModel::formatValue($value, $data['type']);
}
return $fields;
}
/**
* Format a data
*
* @param mixed $value
* @param int $type
*/
public static function formatValue($value, $type, $with_quotes = false)
{
switch ($type)
{
case self::TYPE_INT :
return (int)$value;
case self::TYPE_BOOL :
return (int)$value;
case self::TYPE_FLOAT :
return (float)$value;
case self::TYPE_DATE :
if ($with_quotes)
return '\''.pSQL($value).'\'';
return pSQL($value);
case self::TYPE_HTML :
if ($with_quotes)
return '\''.pSQL($value).'\'';
return pSQL($value);
case self::TYPE_STRING :
default :
if ($with_quotes)
return '\''.pSQL($value).'\'';
return pSQL($value);
}
}
/**
* Save current object to database (add or update)
*
@@ -1198,7 +1205,7 @@ abstract class ObjectModelCore
$reflection = new ReflectionClass($class);
$definition = $reflection->getStaticPropertyValue('definition');
if ($field)
return isset($definition[$field]) ? $definition[$field] : null;
return isset($definition['fields'][$field]) ? $definition['fields'][$field] : null;
return $definition;
}