Skip to content

Commit f48063d

Browse files
committed
updates
- Added `Model::connect(...)` - Detect `deleted_at` field
1 parent 94e3d87 commit f48063d

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/Model.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ public static function instance($arg1, $arg2 = null) {
9090
return self::query_row("SELECT * FROM `$table` WHERE $fields $active_field", $bind);
9191
}
9292

93+
public static function connect($host, $database, $username, $password) {
94+
$db = new \Models\DB(DB_HOST, DB_NAME, DB_USER, DB_PASSWORD);
95+
self::set_db($db);
96+
}
97+
9398
/**
9499
* Set the DB object to our base model class
95100
*
@@ -367,10 +372,16 @@ public function delete() {
367372
$pk = $model['pk'];
368373

369374
// we don't delete here :P
370-
if (self::get_field('active'))
371-
return $this->update('active', 0);
372-
else
375+
if (self::get_field('active')) {
376+
$data = ['active' => 0];
377+
if (self::get_field('deleted_at')) {
378+
$data['deleted_at'] = date('Y-m-d H:i:s');
379+
}
380+
381+
return $this->update($data);
382+
} else {
373383
return self::$db->delete("DELETE FROM $table WHERE $pk = :pk", [':pk' => $this->{$pk}]);
384+
}
374385
}
375386

376387
/**
@@ -403,7 +414,6 @@ public function to_array($get_fields = null) {
403414
$result = [];
404415
$properties = get_object_vars($this);
405416

406-
407417
foreach ($properties as $field => $value) {
408418
if (!$get_fields || ($get_fields && in_array($field, $get_fields))) {
409419
$this->_set_type($field, $value);

0 commit comments

Comments
 (0)