|
@@ -97,26 +97,33 @@ abstract class Entity {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private function create() {
|
|
private function create() {
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
|
|
+ //First, let's verify id polices
|
|
|
|
|
+ //Manual and empty don't need special treatments
|
|
|
if (!empty(static::_idPolice) && static::_idPolice['type'] != 'manual') {
|
|
if (!empty(static::_idPolice) && static::_idPolice['type'] != 'manual') {
|
|
|
|
|
+ //Get the actual max value of the key
|
|
|
$maxVal = DBInstance::queryOne("SELECT max(id) as id FROM {" . static::tableName . "}");
|
|
$maxVal = DBInstance::queryOne("SELECT max(id) as id FROM {" . static::tableName . "}");
|
|
|
$maxVal = ($maxVal) ? $maxVal : 0;
|
|
$maxVal = ($maxVal) ? $maxVal : 0;
|
|
|
|
|
|
|
|
- if (isset(static::_idPolice['min']) && static::_idPolice['min'] > $maxVal->id) {
|
|
|
|
|
|
|
+ // If the next val is smaller than the minumum value
|
|
|
|
|
+ if (isset(static::_idPolice['min']) && static::_idPolice['min'] > $maxVal->id+1) {
|
|
|
|
|
+ // The id value shpuld assume the min value
|
|
|
$this->id = static::_idPolice['min'];
|
|
$this->id = static::_idPolice['min'];
|
|
|
} else {
|
|
} else {
|
|
|
|
|
+ // The id is bigger than the min or min is not set
|
|
|
if (isset(static::_idPolice['step'])) {
|
|
if (isset(static::_idPolice['step'])) {
|
|
|
|
|
+ //If sted is defined, increment by step multiples
|
|
|
$this->id = $maxVal->id + static::_idPolice['step'];
|
|
$this->id = $maxVal->id + static::_idPolice['step'];
|
|
|
} else {
|
|
} else {
|
|
|
$this->id = $maxVal->id + 1;
|
|
$this->id = $maxVal->id + 1;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ //If the id is bigger than the max value. There is problems
|
|
|
if (isset(static::_idPolice['max']) && $maxVal->id > static::_idPolice['max']) {
|
|
if (isset(static::_idPolice['max']) && $maxVal->id > static::_idPolice['max']) {
|
|
|
|
|
+ //Do not store the register
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- var_dump($this);
|
|
|
|
|
|
|
+
|
|
|
$columns = array_diff(array_keys(get_object_vars($this)), static::_ignore);
|
|
$columns = array_diff(array_keys(get_object_vars($this)), static::_ignore);
|
|
|
$obj = (array) $this;
|
|
$obj = (array) $this;
|
|
|
|
|
|
|
@@ -137,6 +144,7 @@ abstract class Entity {
|
|
|
$sql = "INSERT INTO {" . static::tableName . "} ($first_argument) VALUES ($second_argument)";
|
|
$sql = "INSERT INTO {" . static::tableName . "} ($first_argument) VALUES ($second_argument)";
|
|
|
|
|
|
|
|
DBInstance::execute($sql, $insert_data, static::connectionName);
|
|
DBInstance::execute($sql, $insert_data, static::connectionName);
|
|
|
|
|
+ // If there is a id pollice applied, do not get the inserted id
|
|
|
if ( empty(static::_idPolice) ){
|
|
if ( empty(static::_idPolice) ){
|
|
|
$this->id = DBInstance::lastInsert();
|
|
$this->id = DBInstance::lastInsert();
|
|
|
}
|
|
}
|