added nicer overview and delete function

This commit is contained in:
2023-10-26 17:50:54 +02:00
parent 0f13bdea27
commit ddf13b2413
8 changed files with 81 additions and 23 deletions

View File

@ -57,9 +57,13 @@ class Model {
public function save()
{
$newgen = false;
if (!$this->id)
{
$this->id = gen_ulid();
if (!$this->validate())
$newgen = true;
}
if (!$this->validate($newgen))
return false;
foreach($this->dbFields as $field=>$options)
{
@ -111,7 +115,7 @@ class Model {
/**
* @param array $data
*/
private function validate()
private function validate($newgen=false)
{
if (!$this->dbFields)
return true;
@ -133,8 +137,8 @@ class Model {
if (is_array($value))
continue;
if (isset($desc[0]))
$type = $desc[0];
// if (isset($desc[0]))
// $type = $desc[0];
if (in_array('required',$options))
$required = true;
@ -149,8 +153,11 @@ class Model {
$this->data[$key] = $value;
}
if($options['default']!==null && $value===null)
if($options['default']!==null && $newgen === true && !$value)
{
$value = $options['default'];
$this->data[$key] = $value;
}
if ($required && strlen($value) == 0) {
throw new Exception($this->dbTable . "." . $key . " is required");